From 2debfb1267f704cf99fc70845b6bee39a1c1872b Mon Sep 17 00:00:00 2001 From: hamish taylor Date: Mon, 8 May 2023 14:08:40 +1200 Subject: [PATCH 01/23] Extended RaygunEnvironmentMessage to add Maui specific information. Created a custom RaygunClient that uses a new method of building the RaygunMessage --- .../Raygun4Maui.SampleApp.csproj | 5 +- Raygun4Maui/Raygun4MauiExtensions.cs | 2 +- Raygun4Maui/RaygunClientTest.cs | 76 +++++++++++++++++++ Raygun4Maui/RaygunMauiClient.cs | 43 ++++++++++- Raygun4Maui/RaygunMauiEnvironmentMessage.cs | 23 ++++++ Raygun4Maui/raygun4maui.csproj | 9 ++- 6 files changed, 151 insertions(+), 7 deletions(-) create mode 100644 Raygun4Maui/RaygunClientTest.cs create mode 100644 Raygun4Maui/RaygunMauiEnvironmentMessage.cs diff --git a/Raygun4Maui.SampleApp/Raygun4Maui.SampleApp.csproj b/Raygun4Maui.SampleApp/Raygun4Maui.SampleApp.csproj index 2345dac..5268b70 100644 --- a/Raygun4Maui.SampleApp/Raygun4Maui.SampleApp.csproj +++ b/Raygun4Maui.SampleApp/Raygun4Maui.SampleApp.csproj @@ -85,7 +85,10 @@ - + + + + diff --git a/Raygun4Maui/Raygun4MauiExtensions.cs b/Raygun4Maui/Raygun4MauiExtensions.cs index 0d5859c..8446aa7 100644 --- a/Raygun4Maui/Raygun4MauiExtensions.cs +++ b/Raygun4Maui/Raygun4MauiExtensions.cs @@ -10,7 +10,7 @@ public static MauiAppBuilder AddRaygun4Maui( this MauiAppBuilder mauiAppBuilder, Raygun4MauiSettings raygunMauiSettings) { - RaygunMauiClient.Attach(new RaygunClient(raygunMauiSettings)); + RaygunMauiClient.Attach(new RaygunClientTest(raygunMauiSettings)); return mauiAppBuilder .AddRaygunUnhandledExceptionsListener(raygunMauiSettings) .AddRaygunLogger(raygunMauiSettings); diff --git a/Raygun4Maui/RaygunClientTest.cs b/Raygun4Maui/RaygunClientTest.cs new file mode 100644 index 0000000..9dcbd6b --- /dev/null +++ b/Raygun4Maui/RaygunClientTest.cs @@ -0,0 +1,76 @@ +using Mindscape.Raygun4Net; +using System; +using System.Collections; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; +using System.Runtime.InteropServices; + +namespace Raygun4Maui +{ + internal class RaygunClientTest : RaygunClient + { + public RaygunClientTest(string apiKey) : base(apiKey) + { + } + + public RaygunClientTest(RaygunSettings settings) : base(settings) + { + } + + protected override async Task BuildMessage(Exception exception, IList tags, IDictionary userCustomData, RaygunIdentifierMessage userInfo) + { + + DateTime now = DateTime.Now; + + var environment = new RaygunMauiEnvironmentMessage //can also mostlikely be static + { + UtcOffset = TimeZoneInfo.Local.GetUtcOffset(now).TotalHours, + Locale = CultureInfo.CurrentCulture.DisplayName, + OSVersion = DeviceInfo.Current.VersionString, + Architecture = RuntimeInformation.ProcessArchitecture.ToString(), + WindowBoundsWidth = DeviceDisplay.MainDisplayInfo.Width, + WindowBoundsHeight = DeviceDisplay.MainDisplayInfo.Height, + DeviceManufacturer = DeviceInfo.Current.Manufacturer, + OS = DeviceInfo.Current.Platform.ToString(), + }; + + var client = new RaygunClientMessage //This should be set statically + { + Name = "Raygun4Maui", + Version = Assembly.GetExecutingAssembly().GetName().Version.ToString(), + ClientUrl = "https://github.com/MindscapeHQ/raygun4maui" + }; + + var details = new RaygunMessageDetails + { + MachineName = Environment.MachineName, + Client = client, + Error = RaygunErrorMessageBuilder.Build(exception), + UserCustomData = userCustomData, + Tags = tags, + Version = ApplicationVersion, + User = userInfo ?? UserInfo ?? (!String.IsNullOrEmpty(User) ? new RaygunIdentifierMessage(User) : null), + Environment = environment + }; + + var message = new RaygunMessage + { + OccurredOn = DateTime.UtcNow, + Details = details + }; + + var customGroupingKey = await OnCustomGroupingKey(exception, message).ConfigureAwait(false); + + if (string.IsNullOrEmpty(customGroupingKey) == false) + { + message.Details.GroupingKey = customGroupingKey; + } + + return message; + } + } +} diff --git a/Raygun4Maui/RaygunMauiClient.cs b/Raygun4Maui/RaygunMauiClient.cs index 776e36d..94fb751 100644 --- a/Raygun4Maui/RaygunMauiClient.cs +++ b/Raygun4Maui/RaygunMauiClient.cs @@ -1,12 +1,22 @@ using System.Reflection; using Mindscape.Raygun4Net; +using System.Runtime.InteropServices; +using System.Globalization; +using System.Runtime.CompilerServices; +using Microsoft.Maui.Platform; +using Microsoft.Maui.Devices; +#if ANDROID +using Android.App; +using Android.Content; +using Android.OS; +#endif namespace Raygun4Maui { public static class RaygunMauiClient { - private static RaygunClient _instance; + private static RaygunClientTest _instance; private static readonly string clientName = "Raygun4Maui"; @@ -14,9 +24,31 @@ public static class RaygunMauiClient private static readonly string clientUrl = "https://github.com/MindscapeHQ/raygun4maui"; +/* private static readonly RaygunEnvironmentMessage environmentMessage = new RaygunEnvironmentMessage + { + ProcessorCount = System.Environment.ProcessorCount, + OSVersion = DeviceInfo.Current.VersionString, + //Cpu = DeviceInfo.Model, // Might not be the exact CPU, but closest we can get + Architecture = RuntimeInformation.ProcessArchitecture.ToString(), + *//* TotalVirtualMemory = 0, // Not exactly virtual memory, but total managed heap size + AvailableVirtualMemory = 0,*//* + DiskSpaceFree = new List(), + UtcOffset = DateTimeOffset.Now.Offset.TotalHours, + Locale = CultureInfo.CurrentCulture.DisplayName, + };*/ + +/* static RaygunMauiClient() + { + var displayInfo = DeviceDisplay.MainDisplayInfo; + environmentMessage.WindowBoundsWidth = displayInfo.Width; + environmentMessage.WindowBoundsHeight = displayInfo.Height; + + } +*/ + public static RaygunClient Current => _instance; - internal static void Attach(RaygunClient client) + internal static void Attach(RaygunClientTest client) { if (_instance != null) { @@ -24,7 +56,7 @@ internal static void Attach(RaygunClient client) } _instance = client; - client.SendingMessage += OnSendingMessage; + //client.SendingMessage += OnSendingMessage; } private static void OnSendingMessage(object sender, RaygunSendingMessageEventArgs e) @@ -35,6 +67,11 @@ private static void OnSendingMessage(object sender, RaygunSendingMessageEventArg e.Message.Details.Client.Name = clientName; e.Message.Details.Client.Version = clientVersion; e.Message.Details.Client.ClientUrl = clientUrl; + e.Message.Details.Environment.OSVersion = DeviceInfo.Current.VersionString; //IS THIS CORRECT? + //e.Message.Details.Environment = environmentMessage; + + + } } } diff --git a/Raygun4Maui/RaygunMauiEnvironmentMessage.cs b/Raygun4Maui/RaygunMauiEnvironmentMessage.cs new file mode 100644 index 0000000..819952a --- /dev/null +++ b/Raygun4Maui/RaygunMauiEnvironmentMessage.cs @@ -0,0 +1,23 @@ +using Mindscape.Raygun4Net; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Raygun4Maui +{ + internal class RaygunMauiEnvironmentMessage : RaygunEnvironmentMessage + { + public int ScreenWidth { get; set; } + public int ScreenHeight { get; set; } + public double ResolutionScale { get; set; } + public int ColorDepth { get; set; } + public string CurrentOrientation { get; set; } + public string DeviceManufacturer { get; set; } + public string Model { get; set; } + public string DeviceName { get; set; } + public string Platform { get; set; } + public string OS { get; set; } + } +} diff --git a/Raygun4Maui/raygun4maui.csproj b/Raygun4Maui/raygun4maui.csproj index ec67c9c..25b97fc 100644 --- a/Raygun4Maui/raygun4maui.csproj +++ b/Raygun4Maui/raygun4maui.csproj @@ -16,7 +16,7 @@ 10.0.17763.0 6.5 True - 1.1.0 + 1.1.1 Raygun Raygun README.md @@ -25,7 +25,7 @@ https://raygun.com/platform/crash-reporting https://github.com/MindscapeHQ/raygun4maui Raygun4Maui; Raygun; Crash Reporting; MAUI; .NET; dotnet - Support for reporting MAUI .NET unhandled exception and ILogger logs to Raygun with single-step easy-to-use extension method + Brought feature parity with the Raygun4net.core provider Raygun4Maui LICENSE True @@ -122,4 +122,9 @@ + + + + + From 98973e9e3d0ee97a796772f57fdb0ab403963d48 Mon Sep 17 00:00:00 2001 From: hamish taylor Date: Mon, 8 May 2023 16:31:34 +1200 Subject: [PATCH 02/23] Added some Android specific initialisation. Added NativeDeviceInfo class to enable easy access to device info. Cleaned up The RaygunMauiClient --- Raygun4Maui/NativeDeviceInfo.cs | 77 +++++++++++++++++++++ Raygun4Maui/RaygunClientTest.cs | 24 +++++-- Raygun4Maui/RaygunMauiClient.cs | 45 +----------- Raygun4Maui/RaygunMauiEnvironmentMessage.cs | 4 -- Raygun4Maui/raygun4maui.csproj | 5 -- 5 files changed, 98 insertions(+), 57 deletions(-) create mode 100644 Raygun4Maui/NativeDeviceInfo.cs diff --git a/Raygun4Maui/NativeDeviceInfo.cs b/Raygun4Maui/NativeDeviceInfo.cs new file mode 100644 index 0000000..846b7a5 --- /dev/null +++ b/Raygun4Maui/NativeDeviceInfo.cs @@ -0,0 +1,77 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Raygun4Maui +{ + internal static class NativeDeviceInfo + { + + + + public static ulong TotalPhysicalMemory() + { +#if WINDOWS + return 0; +#elif ANDROID + var runtime = Java.Lang.Runtime.GetRuntime(); + if (runtime != null) + { + return (ulong)runtime.TotalMemory(); + } + else + { + return 0; + } +#elif IOS + return 0; +#elif MACCATALYST + return 0; + +#else + return 0; +#endif + } + + + public static ulong AvailablePhysicalMemory() + { +#if WINDOWS + return 0; +#elif ANDROID + var runtime = Java.Lang.Runtime.GetRuntime(); + if (runtime != null) + { + return (ulong)runtime.FreeMemory(); + } + else + { + return 0; + } +#elif IOS + return 0; +#elif MACCATALYST + return 0; +#else + return 0; +#endif + } + + public static string Platform() + { +#if WINDOWS + return "Windows"; +#elif ANDROID + return "Android"; +#elif IOS + return "iOS"; +#elif MACCATALYST + return "MacCatalyst"; +#else + return "Unknown"; +#endif + } + } +} diff --git a/Raygun4Maui/RaygunClientTest.cs b/Raygun4Maui/RaygunClientTest.cs index 9dcbd6b..489b7a3 100644 --- a/Raygun4Maui/RaygunClientTest.cs +++ b/Raygun4Maui/RaygunClientTest.cs @@ -21,12 +21,12 @@ public RaygunClientTest(RaygunSettings settings) : base(settings) { } + protected override async Task BuildMessage(Exception exception, IList tags, IDictionary userCustomData, RaygunIdentifierMessage userInfo) { DateTime now = DateTime.Now; - - var environment = new RaygunMauiEnvironmentMessage //can also mostlikely be static + var environment = new RaygunMauiEnvironmentMessage //Mostlikely should be static { UtcOffset = TimeZoneInfo.Local.GetUtcOffset(now).TotalHours, Locale = CultureInfo.CurrentCulture.DisplayName, @@ -35,9 +35,25 @@ protected override async Task BuildMessage(Exception exception, I WindowBoundsWidth = DeviceDisplay.MainDisplayInfo.Width, WindowBoundsHeight = DeviceDisplay.MainDisplayInfo.Height, DeviceManufacturer = DeviceInfo.Current.Manufacturer, - OS = DeviceInfo.Current.Platform.ToString(), + Platform = NativeDeviceInfo.Platform(), + Model = DeviceInfo.Current.Model, + ProcessorCount = Environment.ProcessorCount, + ResolutionScale = DeviceDisplay.MainDisplayInfo.Density, + TotalPhysicalMemory = NativeDeviceInfo.TotalPhysicalMemory(), + AvailablePhysicalMemory = NativeDeviceInfo.AvailablePhysicalMemory(), }; +#if WINDOWS + + + +#elif ANDROID + environment.CurrentOrientation = DeviceDisplay.MainDisplayInfo.Orientation.ToString(); +#elif IOS + +#elif MACCATALYST + +#endif var client = new RaygunClientMessage //This should be set statically { Name = "Raygun4Maui", @@ -47,7 +63,7 @@ protected override async Task BuildMessage(Exception exception, I var details = new RaygunMessageDetails { - MachineName = Environment.MachineName, + MachineName = DeviceInfo.Current.Name, Client = client, Error = RaygunErrorMessageBuilder.Build(exception), UserCustomData = userCustomData, diff --git a/Raygun4Maui/RaygunMauiClient.cs b/Raygun4Maui/RaygunMauiClient.cs index 94fb751..1ef4e3d 100644 --- a/Raygun4Maui/RaygunMauiClient.cs +++ b/Raygun4Maui/RaygunMauiClient.cs @@ -17,35 +17,6 @@ namespace Raygun4Maui public static class RaygunMauiClient { private static RaygunClientTest _instance; - - private static readonly string clientName = "Raygun4Maui"; - - private static readonly string clientVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString(); - - private static readonly string clientUrl = "https://github.com/MindscapeHQ/raygun4maui"; - -/* private static readonly RaygunEnvironmentMessage environmentMessage = new RaygunEnvironmentMessage - { - ProcessorCount = System.Environment.ProcessorCount, - OSVersion = DeviceInfo.Current.VersionString, - //Cpu = DeviceInfo.Model, // Might not be the exact CPU, but closest we can get - Architecture = RuntimeInformation.ProcessArchitecture.ToString(), - *//* TotalVirtualMemory = 0, // Not exactly virtual memory, but total managed heap size - AvailableVirtualMemory = 0,*//* - DiskSpaceFree = new List(), - UtcOffset = DateTimeOffset.Now.Offset.TotalHours, - Locale = CultureInfo.CurrentCulture.DisplayName, - };*/ - -/* static RaygunMauiClient() - { - var displayInfo = DeviceDisplay.MainDisplayInfo; - environmentMessage.WindowBoundsWidth = displayInfo.Width; - environmentMessage.WindowBoundsHeight = displayInfo.Height; - - } -*/ - public static RaygunClient Current => _instance; internal static void Attach(RaygunClientTest client) @@ -56,22 +27,8 @@ internal static void Attach(RaygunClientTest client) } _instance = client; - //client.SendingMessage += OnSendingMessage; - } - - private static void OnSendingMessage(object sender, RaygunSendingMessageEventArgs e) - { - //set the machine name to the device name, this is important for mobile - e.Message.Details.MachineName = DeviceInfo.Current.Name; - //set the libary information, without this it will show as a .NET client - e.Message.Details.Client.Name = clientName; - e.Message.Details.Client.Version = clientVersion; - e.Message.Details.Client.ClientUrl = clientUrl; - e.Message.Details.Environment.OSVersion = DeviceInfo.Current.VersionString; //IS THIS CORRECT? - //e.Message.Details.Environment = environmentMessage; - - } + } } diff --git a/Raygun4Maui/RaygunMauiEnvironmentMessage.cs b/Raygun4Maui/RaygunMauiEnvironmentMessage.cs index 819952a..b50ab07 100644 --- a/Raygun4Maui/RaygunMauiEnvironmentMessage.cs +++ b/Raygun4Maui/RaygunMauiEnvironmentMessage.cs @@ -9,15 +9,11 @@ namespace Raygun4Maui { internal class RaygunMauiEnvironmentMessage : RaygunEnvironmentMessage { - public int ScreenWidth { get; set; } - public int ScreenHeight { get; set; } public double ResolutionScale { get; set; } - public int ColorDepth { get; set; } public string CurrentOrientation { get; set; } public string DeviceManufacturer { get; set; } public string Model { get; set; } public string DeviceName { get; set; } public string Platform { get; set; } - public string OS { get; set; } } } diff --git a/Raygun4Maui/raygun4maui.csproj b/Raygun4Maui/raygun4maui.csproj index 25b97fc..9cac0a9 100644 --- a/Raygun4Maui/raygun4maui.csproj +++ b/Raygun4Maui/raygun4maui.csproj @@ -122,9 +122,4 @@ - - - - - From 8b0d1e929c5c738733875b6d3b7d20f22512b177 Mon Sep 17 00:00:00 2001 From: hamish taylor Date: Tue, 9 May 2023 10:13:19 +1200 Subject: [PATCH 03/23] Added Android and iOS specific device information. --- Raygun4Maui/NativeDeviceInfo.cs | 104 +++++++++++++++++++++++++++++--- Raygun4Maui/RaygunClientTest.cs | 4 +- Raygun4Maui/raygun4maui.csproj | 1 + 3 files changed, 100 insertions(+), 9 deletions(-) diff --git a/Raygun4Maui/NativeDeviceInfo.cs b/Raygun4Maui/NativeDeviceInfo.cs index 846b7a5..9d227d7 100644 --- a/Raygun4Maui/NativeDeviceInfo.cs +++ b/Raygun4Maui/NativeDeviceInfo.cs @@ -1,13 +1,68 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.Runtime.InteropServices; + +#if ANDROID +using Android.App; +using Android.Content; +using Android.Content.Res; +using Android.OS; +using Android.Runtime; +using Android.Views; +using Android.Provider; +#elif IOS +using Foundation; +using UIKit; +using ObjCRuntime; +#endif + namespace Raygun4Maui { internal static class NativeDeviceInfo { + private const string MEM_AVAILABLE_PROP_NAME = "hw.usermem"; + private const string MEM_TOTAL_PROP_NAME = "hw.physmem"; +#if IOS + [DllImport(ObjCRuntime.Constants.SystemLibrary)] + private static extern int sysctlbyname([MarshalAs(UnmanagedType.LPStr)] string property, IntPtr output, IntPtr oldLen, IntPtr newp, uint newlen); + + private static uint GetUIntSysCtl(string propertyName) + { + // get the length of the string that will be returned + var pLen = Marshal.AllocHGlobal(sizeof(int)); + sysctlbyname(propertyName, IntPtr.Zero, pLen, IntPtr.Zero, 0); + + var length = Marshal.ReadInt32(pLen); + + // check to see if we got a length + if (length <= 0) + { + Marshal.FreeHGlobal(pLen); + return 0; + } + + // get the hardware string + var pStr = Marshal.AllocHGlobal(length); + sysctlbyname(propertyName, pStr, pLen, IntPtr.Zero, 0); + + // convert the native string into a C# integer + + var memoryCount = Marshal.ReadInt32(pStr); + uint memoryVal = (uint)memoryCount; + + if (memoryCount < 0) + { + memoryVal = (uint)((uint)int.MaxValue + (-memoryCount)); + } + + var ret = memoryVal; + + // cleanup + Marshal.FreeHGlobal(pLen); + Marshal.FreeHGlobal(pStr); + + return ret; + } +#endif @@ -26,7 +81,7 @@ public static ulong TotalPhysicalMemory() return 0; } #elif IOS - return 0; + return GetUIntSysCtl(MEM_TOTAL_PROP_NAME); #elif MACCATALYST return 0; @@ -51,7 +106,7 @@ public static ulong AvailablePhysicalMemory() return 0; } #elif IOS - return 0; + return GetUIntSysCtl(MEM_AVAILABLE_PROP_NAME); #elif MACCATALYST return 0; #else @@ -71,6 +126,41 @@ public static string Platform() return "MacCatalyst"; #else return "Unknown"; +#endif + } + + public static string MachineName() + { +#if IOS + return UIDevice.CurrentDevice.Name; +#elif MACCATALYST + return "MacCatalyst"; +#else + return DeviceInfo.Current.Name; +#endif + } + + public static string Architecture() + { +#if WINDOWS + return RuntimeInformation.ProcessArchitecture.ToString(); +#elif ANDROID + var supportedABIs = Build.SupportedAbis; + if (supportedABIs != null && supportedABIs.Count > 0) + { + return supportedABIs[0]; + } + else + { + return RuntimeInformation.ProcessArchitecture.ToString(); + } + +#elif IOS + return RuntimeInformation.ProcessArchitecture.ToString(); +#elif MACCATALYST + return RuntimeInformation.ProcessArchitecture.ToString(); +#else + return RuntimeInformation.ProcessArchitecture.ToString(); #endif } } diff --git a/Raygun4Maui/RaygunClientTest.cs b/Raygun4Maui/RaygunClientTest.cs index 489b7a3..43dd501 100644 --- a/Raygun4Maui/RaygunClientTest.cs +++ b/Raygun4Maui/RaygunClientTest.cs @@ -31,7 +31,7 @@ protected override async Task BuildMessage(Exception exception, I UtcOffset = TimeZoneInfo.Local.GetUtcOffset(now).TotalHours, Locale = CultureInfo.CurrentCulture.DisplayName, OSVersion = DeviceInfo.Current.VersionString, - Architecture = RuntimeInformation.ProcessArchitecture.ToString(), + Architecture = NativeDeviceInfo.Architecture(), WindowBoundsWidth = DeviceDisplay.MainDisplayInfo.Width, WindowBoundsHeight = DeviceDisplay.MainDisplayInfo.Height, DeviceManufacturer = DeviceInfo.Current.Manufacturer, @@ -63,7 +63,7 @@ protected override async Task BuildMessage(Exception exception, I var details = new RaygunMessageDetails { - MachineName = DeviceInfo.Current.Name, + MachineName = NativeDeviceInfo.MachineName(), Client = client, Error = RaygunErrorMessageBuilder.Build(exception), UserCustomData = userCustomData, diff --git a/Raygun4Maui/raygun4maui.csproj b/Raygun4Maui/raygun4maui.csproj index 9cac0a9..6a641db 100644 --- a/Raygun4Maui/raygun4maui.csproj +++ b/Raygun4Maui/raygun4maui.csproj @@ -30,6 +30,7 @@ LICENSE True Raygun-icon-128x128.png + 54661550-a31d-44d7-a748-7ac67fc82450 From 5a234b632bf6fea7d597c594c0869f45542b858c Mon Sep 17 00:00:00 2001 From: Hamish Date: Tue, 9 May 2023 11:11:36 +1200 Subject: [PATCH 04/23] Added Mac specific device info. --- Raygun4Maui/NativeDeviceInfo.cs | 60 ++++++++++++++++++++++++++------- 1 file changed, 48 insertions(+), 12 deletions(-) diff --git a/Raygun4Maui/NativeDeviceInfo.cs b/Raygun4Maui/NativeDeviceInfo.cs index 9d227d7..485af4d 100644 --- a/Raygun4Maui/NativeDeviceInfo.cs +++ b/Raygun4Maui/NativeDeviceInfo.cs @@ -8,7 +8,7 @@ using Android.Runtime; using Android.Views; using Android.Provider; -#elif IOS +#elif IOS || MACCATALYST using Foundation; using UIKit; using ObjCRuntime; @@ -21,7 +21,8 @@ internal static class NativeDeviceInfo { private const string MEM_AVAILABLE_PROP_NAME = "hw.usermem"; private const string MEM_TOTAL_PROP_NAME = "hw.physmem"; -#if IOS + private const string MACHINE_PROP_NAME = "hw.machine"; +#if IOS || MACCATALYST [DllImport(ObjCRuntime.Constants.SystemLibrary)] private static extern int sysctlbyname([MarshalAs(UnmanagedType.LPStr)] string property, IntPtr output, IntPtr oldLen, IntPtr newp, uint newlen); @@ -62,9 +63,51 @@ private static uint GetUIntSysCtl(string propertyName) return ret; } -#endif + + private static string GetStringSysCtl(string propertyName) + { + // get the length of the string that will be returned + var pLen = Marshal.AllocHGlobal(sizeof(int)); + sysctlbyname(propertyName, IntPtr.Zero, pLen, IntPtr.Zero, 0); + + var length = Marshal.ReadInt32(pLen); + + // check to see if we got a length + if (length <= 0) + { + Marshal.FreeHGlobal(pLen); + return "Unknown"; + } + + // get the hardware string + var pStr = Marshal.AllocHGlobal(length); + sysctlbyname(propertyName, pStr, pLen, IntPtr.Zero, 0); + + // convert the native string into a C# integer + + var hardwareStr = Marshal.PtrToStringAnsi(pStr); + // cleanup + Marshal.FreeHGlobal(pLen); + Marshal.FreeHGlobal(pStr); + + return hardwareStr; + } +#endif + + public static string Model() + { +#if WINDOWS +return DeviceInfo.Current.Model; +#elif ANDROID +return DeviceInfo.Current.Model; +#elif IOS || MACCATALYST +return GetStringSysCtl(MACHINE_PROP_NAME); +#else + return "unknown"; +#endif + } public static ulong TotalPhysicalMemory() { @@ -80,11 +123,8 @@ public static ulong TotalPhysicalMemory() { return 0; } -#elif IOS +#elif IOS || MACCATALYST return GetUIntSysCtl(MEM_TOTAL_PROP_NAME); -#elif MACCATALYST - return 0; - #else return 0; #endif @@ -105,10 +145,8 @@ public static ulong AvailablePhysicalMemory() { return 0; } -#elif IOS +#elif IOS || MACCATALYST return GetUIntSysCtl(MEM_AVAILABLE_PROP_NAME); -#elif MACCATALYST - return 0; #else return 0; #endif @@ -133,8 +171,6 @@ public static string MachineName() { #if IOS return UIDevice.CurrentDevice.Name; -#elif MACCATALYST - return "MacCatalyst"; #else return DeviceInfo.Current.Name; #endif From 49380f9465d97fd1a79fecf45ad550c6ab2ca1fc Mon Sep 17 00:00:00 2001 From: hamish taylor Date: Tue, 9 May 2023 11:43:56 +1200 Subject: [PATCH 05/23] Removed unused android imports. --- Raygun4Maui.SampleApp/MauiProgram.cs | 8 ++++---- Raygun4Maui/NativeDeviceInfo.cs | 6 ------ 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/Raygun4Maui.SampleApp/MauiProgram.cs b/Raygun4Maui.SampleApp/MauiProgram.cs index a9a605e..5120df7 100644 --- a/Raygun4Maui.SampleApp/MauiProgram.cs +++ b/Raygun4Maui.SampleApp/MauiProgram.cs @@ -5,8 +5,8 @@ namespace Raygun4Maui.SampleApp; public static class MauiProgram { - public static MauiApp CreateMauiApp() - { + public static MauiApp CreateMauiApp() + { var configuration = new ConfigurationBuilder() .AddUserSecrets() .Build(); @@ -22,8 +22,8 @@ public static MauiApp CreateMauiApp() { fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular"); fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold"); - }).AddRaygun4Maui(apiKey) ; + }).AddRaygun4Maui(apiKey); return builder.Build(); - } + } } diff --git a/Raygun4Maui/NativeDeviceInfo.cs b/Raygun4Maui/NativeDeviceInfo.cs index 485af4d..53de90d 100644 --- a/Raygun4Maui/NativeDeviceInfo.cs +++ b/Raygun4Maui/NativeDeviceInfo.cs @@ -1,13 +1,7 @@ using System.Runtime.InteropServices; #if ANDROID -using Android.App; -using Android.Content; -using Android.Content.Res; using Android.OS; -using Android.Runtime; -using Android.Views; -using Android.Provider; #elif IOS || MACCATALYST using Foundation; using UIKit; From d36a39279b103deff5ebf24fb756d6aafc17c40e Mon Sep 17 00:00:00 2001 From: hamish taylor Date: Tue, 9 May 2023 13:59:09 +1200 Subject: [PATCH 06/23] Renamed RaygunClientTest to RaygunClient. --- Raygun4Maui.SampleApp/MauiProgram.cs | 3 +- Raygun4Maui.Tests/Raygun4Maui.Tests.csproj | 40 ----------------- Raygun4Maui.Tests/TestRaygun4MauiSettings.cs | 12 ------ Raygun4Maui.Tests/Usings.cs | 1 - Raygun4Maui/Raygun4MauiExtensions.cs | 2 +- .../{RaygunClientTest.cs => RaygunClient.cs} | 43 ++++++------------- Raygun4Maui/RaygunMauiClient.cs | 4 +- Raygun4Maui/raygun4maui.sln | 12 +++--- 8 files changed, 23 insertions(+), 94 deletions(-) delete mode 100644 Raygun4Maui.Tests/Raygun4Maui.Tests.csproj delete mode 100644 Raygun4Maui.Tests/TestRaygun4MauiSettings.cs delete mode 100644 Raygun4Maui.Tests/Usings.cs rename Raygun4Maui/{RaygunClientTest.cs => RaygunClient.cs} (73%) diff --git a/Raygun4Maui.SampleApp/MauiProgram.cs b/Raygun4Maui.SampleApp/MauiProgram.cs index 5120df7..b4504ec 100644 --- a/Raygun4Maui.SampleApp/MauiProgram.cs +++ b/Raygun4Maui.SampleApp/MauiProgram.cs @@ -23,7 +23,6 @@ public static MauiApp CreateMauiApp() fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular"); fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold"); }).AddRaygun4Maui(apiKey); - - return builder.Build(); + return builder.Build(); } } diff --git a/Raygun4Maui.Tests/Raygun4Maui.Tests.csproj b/Raygun4Maui.Tests/Raygun4Maui.Tests.csproj deleted file mode 100644 index f3fc88e..0000000 --- a/Raygun4Maui.Tests/Raygun4Maui.Tests.csproj +++ /dev/null @@ -1,40 +0,0 @@ - - - - net6.0 - enable - enable - - false - - 4f5caf8a-2858-4479-8bd1-2cb157aea4da - - - - True - - - - True - - - - - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - - - - - - - diff --git a/Raygun4Maui.Tests/TestRaygun4MauiSettings.cs b/Raygun4Maui.Tests/TestRaygun4MauiSettings.cs deleted file mode 100644 index 2fa8286..0000000 --- a/Raygun4Maui.Tests/TestRaygun4MauiSettings.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace Raygun4Maui.Tests -{ - [TestClass] - public class TestRaygun4MauiSettings - { - [TestMethod] - public void TestRaygun4MauiSettingsObjectCreation() - { - Assert.IsNotNull(new Raygun4MauiSettings()); - } - } -} diff --git a/Raygun4Maui.Tests/Usings.cs b/Raygun4Maui.Tests/Usings.cs deleted file mode 100644 index ab67c7e..0000000 --- a/Raygun4Maui.Tests/Usings.cs +++ /dev/null @@ -1 +0,0 @@ -global using Microsoft.VisualStudio.TestTools.UnitTesting; \ No newline at end of file diff --git a/Raygun4Maui/Raygun4MauiExtensions.cs b/Raygun4Maui/Raygun4MauiExtensions.cs index 8446aa7..0d5859c 100644 --- a/Raygun4Maui/Raygun4MauiExtensions.cs +++ b/Raygun4Maui/Raygun4MauiExtensions.cs @@ -10,7 +10,7 @@ public static MauiAppBuilder AddRaygun4Maui( this MauiAppBuilder mauiAppBuilder, Raygun4MauiSettings raygunMauiSettings) { - RaygunMauiClient.Attach(new RaygunClientTest(raygunMauiSettings)); + RaygunMauiClient.Attach(new RaygunClient(raygunMauiSettings)); return mauiAppBuilder .AddRaygunUnhandledExceptionsListener(raygunMauiSettings) .AddRaygunLogger(raygunMauiSettings); diff --git a/Raygun4Maui/RaygunClientTest.cs b/Raygun4Maui/RaygunClient.cs similarity index 73% rename from Raygun4Maui/RaygunClientTest.cs rename to Raygun4Maui/RaygunClient.cs index 43dd501..fc2ce1d 100644 --- a/Raygun4Maui/RaygunClientTest.cs +++ b/Raygun4Maui/RaygunClient.cs @@ -1,30 +1,30 @@ using Mindscape.Raygun4Net; -using System; using System.Collections; -using System.Collections.Generic; using System.Globalization; -using System.Linq; using System.Reflection; -using System.Text; -using System.Threading.Tasks; -using System.Runtime.InteropServices; namespace Raygun4Maui { - internal class RaygunClientTest : RaygunClient + public class RaygunClient : Mindscape.Raygun4Net.RaygunClient { - public RaygunClientTest(string apiKey) : base(apiKey) + public RaygunClient(string apiKey) : base(apiKey) { } - public RaygunClientTest(RaygunSettings settings) : base(settings) + public RaygunClient(RaygunSettings settings) : base(settings) { } + public static readonly RaygunClientMessage ClientMessage = new() + { + Name = "Raygun4Maui", + Version = Assembly.GetExecutingAssembly().GetName().Version.ToString(), + ClientUrl = "https://github.com/MindscapeHQ/raygun4maui" + }; + protected override async Task BuildMessage(Exception exception, IList tags, IDictionary userCustomData, RaygunIdentifierMessage userInfo) { - DateTime now = DateTime.Now; var environment = new RaygunMauiEnvironmentMessage //Mostlikely should be static { @@ -41,30 +41,13 @@ protected override async Task BuildMessage(Exception exception, I ResolutionScale = DeviceDisplay.MainDisplayInfo.Density, TotalPhysicalMemory = NativeDeviceInfo.TotalPhysicalMemory(), AvailablePhysicalMemory = NativeDeviceInfo.AvailablePhysicalMemory(), + CurrentOrientation = DeviceDisplay.MainDisplayInfo.Orientation.ToString(), }; - -#if WINDOWS - - - -#elif ANDROID - environment.CurrentOrientation = DeviceDisplay.MainDisplayInfo.Orientation.ToString(); -#elif IOS - -#elif MACCATALYST - -#endif - var client = new RaygunClientMessage //This should be set statically - { - Name = "Raygun4Maui", - Version = Assembly.GetExecutingAssembly().GetName().Version.ToString(), - ClientUrl = "https://github.com/MindscapeHQ/raygun4maui" - }; - + var details = new RaygunMessageDetails { MachineName = NativeDeviceInfo.MachineName(), - Client = client, + Client = ClientMessage, Error = RaygunErrorMessageBuilder.Build(exception), UserCustomData = userCustomData, Tags = tags, diff --git a/Raygun4Maui/RaygunMauiClient.cs b/Raygun4Maui/RaygunMauiClient.cs index 1ef4e3d..93d3439 100644 --- a/Raygun4Maui/RaygunMauiClient.cs +++ b/Raygun4Maui/RaygunMauiClient.cs @@ -16,10 +16,10 @@ namespace Raygun4Maui { public static class RaygunMauiClient { - private static RaygunClientTest _instance; + private static RaygunClient _instance; public static RaygunClient Current => _instance; - internal static void Attach(RaygunClientTest client) + internal static void Attach(RaygunClient client) { if (_instance != null) { diff --git a/Raygun4Maui/raygun4maui.sln b/Raygun4Maui/raygun4maui.sln index d27e692..f6c65e4 100644 --- a/Raygun4Maui/raygun4maui.sln +++ b/Raygun4Maui/raygun4maui.sln @@ -5,10 +5,10 @@ VisualStudioVersion = 17.3.32819.101 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Raygun4Maui", "Raygun4Maui.csproj", "{DFFC7DE6-7DD6-4ADD-B727-7CF90DDC527C}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Raygun4Maui.Tests", "..\Raygun4Maui.Tests\Raygun4Maui.Tests.csproj", "{333CA348-9B0A-4986-8EEE-F5ED031F3082}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Raygun4Maui.SampleApp", "..\Raygun4Maui.SampleApp\Raygun4Maui.SampleApp.csproj", "{005156B2-833B-406B-B5FD-F50593C4D28B}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Raygun4Maui.Test", "..\Raygun4Maui.Test\Raygun4Maui.Test.csproj", "{E288B763-306C-42D6-84DE-49AC6CF889FE}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -19,16 +19,16 @@ Global {DFFC7DE6-7DD6-4ADD-B727-7CF90DDC527C}.Debug|Any CPU.Build.0 = Debug|Any CPU {DFFC7DE6-7DD6-4ADD-B727-7CF90DDC527C}.Release|Any CPU.ActiveCfg = Release|Any CPU {DFFC7DE6-7DD6-4ADD-B727-7CF90DDC527C}.Release|Any CPU.Build.0 = Release|Any CPU - {333CA348-9B0A-4986-8EEE-F5ED031F3082}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {333CA348-9B0A-4986-8EEE-F5ED031F3082}.Debug|Any CPU.Build.0 = Debug|Any CPU - {333CA348-9B0A-4986-8EEE-F5ED031F3082}.Release|Any CPU.ActiveCfg = Release|Any CPU - {333CA348-9B0A-4986-8EEE-F5ED031F3082}.Release|Any CPU.Build.0 = Release|Any CPU {005156B2-833B-406B-B5FD-F50593C4D28B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {005156B2-833B-406B-B5FD-F50593C4D28B}.Debug|Any CPU.Build.0 = Debug|Any CPU {005156B2-833B-406B-B5FD-F50593C4D28B}.Debug|Any CPU.Deploy.0 = Debug|Any CPU {005156B2-833B-406B-B5FD-F50593C4D28B}.Release|Any CPU.ActiveCfg = Release|Any CPU {005156B2-833B-406B-B5FD-F50593C4D28B}.Release|Any CPU.Build.0 = Release|Any CPU {005156B2-833B-406B-B5FD-F50593C4D28B}.Release|Any CPU.Deploy.0 = Release|Any CPU + {E288B763-306C-42D6-84DE-49AC6CF889FE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E288B763-306C-42D6-84DE-49AC6CF889FE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E288B763-306C-42D6-84DE-49AC6CF889FE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E288B763-306C-42D6-84DE-49AC6CF889FE}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE From 32b4ffc6e53d654787dd098685ef00ada7c54067 Mon Sep 17 00:00:00 2001 From: hamish taylor Date: Tue, 9 May 2023 14:07:25 +1200 Subject: [PATCH 07/23] Bumped the version number. --- Raygun4Maui/raygun4maui.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Raygun4Maui/raygun4maui.csproj b/Raygun4Maui/raygun4maui.csproj index 6a641db..fddd566 100644 --- a/Raygun4Maui/raygun4maui.csproj +++ b/Raygun4Maui/raygun4maui.csproj @@ -16,7 +16,7 @@ 10.0.17763.0 6.5 True - 1.1.1 + 1.2.0 Raygun Raygun README.md From 736a7a113f4b36e52ca4f26e6909c55dc3d969e2 Mon Sep 17 00:00:00 2001 From: hamish taylor Date: Tue, 9 May 2023 14:30:47 +1200 Subject: [PATCH 08/23] Updated Readme slightly for new release information. --- README.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index da9eb03..a105249 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ dotnet add package Raygun4Maui Alternatively you can specify a version tag to install a specific version of the package, see [Raygun4Maui NuGet Gallery page](https://nuget.org/packages/Raygun4Maui) for information of versions. ``` -dotnet add package Raygun4Maui --version 1.0.0 +dotnet add package Raygun4Maui --version 1.2.0 ``` ### Step 2 - Add Raygun4Maui to your MauiApp builder @@ -76,17 +76,17 @@ builder Unhandled exceptions will be sent to Raygun automatically. -Raygun4Maui stores an instance of a [Raygun4Net](https://github.com/MindscapeHQ/raygun4net/tree/master/Mindscape.Raygun4Net.NetCore). `RaygunClient` object, this can be accessed through the following code: +Raygun4Maui stores an instance of a `RaygunClient` object, this can be accessed through the following code: ``` csharp RaygunMauiClient.Current ``` -Any features supported by the Raygun4Net Client are accessible here +This client extends the Raygun4Net.NetCore `RaygunClient`, as a result any features supported by the Raygun4Net.NetCore Client are supported here. --- ### Manually sending exceptions -Raygun4Maui automatically sends unhandled exceptions. For manual sending, use Send or SendInBackground methods, as shown below: +Raygun4Maui automatically sends unhandled exceptions. For manual sending, use `Send` or `SendInBackground` methods, as shown below: ``` csharp try { @@ -101,17 +101,17 @@ try { An exception needs to be thrown in order for its stack trace to be populated. If the exception is created manually no stack trace data is collected. ### Other examples -For aditional examples on how to use the Raygun4Net client object refer to its deticated instructions [here](https://github.com/MindscapeHQ/raygun4net/tree/master/Mindscape.Raygun4Net.NetCore) - +For aditional examples on how to use the `RaygunClient` object refer to the [Raygun4Net.NetCore documentation](https://raygun.com/documentation/language-guides/dotnet/crash-reporting/net-core/) ## ILogger logging +Raygun4Maui will automatically send any logger logs to Raygun. -To make a log entry, acquire the reference to the ILogger services that your MAUI app maintains: +To make a log entry, obtain the reference to the ILogger services that your MAUI app maintains: ``` c# ILogger logger = Handler.MauiContext.Services.GetService>(); ``` -You may now invoke the various ILogger log methods from the logger object accordingly. This uses the same `RaygunClient` object accessible from RaygunMauiClient.Current +You may now invoke the various ILogger log methods from the logger object accordingly. This uses the same `RaygunClient` object accessible from `RaygunMauiClient.Current` ```c# logger.LogInformation("Raygun4Maui.SampleApp.TestLoggerErrorsSent: {MethodName} @ {Timestamp}", "TestLogInformation", DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss")); From b73e7c180ab40df243179d7d8d8bd900b8052c0b Mon Sep 17 00:00:00 2001 From: hamish taylor Date: Tue, 9 May 2023 15:53:21 +1200 Subject: [PATCH 09/23] Added Windows specific memory information. --- Raygun4Maui/NativeDeviceInfo.cs | 128 ++++++++++++++++---------------- Raygun4Maui/RaygunClient.cs | 2 +- 2 files changed, 63 insertions(+), 67 deletions(-) diff --git a/Raygun4Maui/NativeDeviceInfo.cs b/Raygun4Maui/NativeDeviceInfo.cs index 53de90d..d336e5b 100644 --- a/Raygun4Maui/NativeDeviceInfo.cs +++ b/Raygun4Maui/NativeDeviceInfo.cs @@ -1,6 +1,8 @@ using System.Runtime.InteropServices; +using System.Diagnostics; +#if WINDOWS -#if ANDROID +#elif ANDROID using Android.OS; #elif IOS || MACCATALYST using Foundation; @@ -20,76 +22,78 @@ internal static class NativeDeviceInfo [DllImport(ObjCRuntime.Constants.SystemLibrary)] private static extern int sysctlbyname([MarshalAs(UnmanagedType.LPStr)] string property, IntPtr output, IntPtr oldLen, IntPtr newp, uint newlen); - private static uint GetUIntSysCtl(string propertyName) - { - // get the length of the string that will be returned - var pLen = Marshal.AllocHGlobal(sizeof(int)); - sysctlbyname(propertyName, IntPtr.Zero, pLen, IntPtr.Zero, 0); + private static uint GetUIntSysCtl(string propertyName) + { + // get the length of the string that will be returned + var pLen = Marshal.AllocHGlobal(sizeof(int)); + sysctlbyname(propertyName, IntPtr.Zero, pLen, IntPtr.Zero, 0); - var length = Marshal.ReadInt32(pLen); + var length = Marshal.ReadInt32(pLen); - // check to see if we got a length - if (length <= 0) - { - Marshal.FreeHGlobal(pLen); - return 0; - } + // check to see if we got a length + if (length <= 0) + { + Marshal.FreeHGlobal(pLen); + return 0; + } - // get the hardware string - var pStr = Marshal.AllocHGlobal(length); - sysctlbyname(propertyName, pStr, pLen, IntPtr.Zero, 0); + // get the hardware string + var pStr = Marshal.AllocHGlobal(length); + sysctlbyname(propertyName, pStr, pLen, IntPtr.Zero, 0); - // convert the native string into a C# integer + // convert the native string into a C# integer - var memoryCount = Marshal.ReadInt32(pStr); - uint memoryVal = (uint)memoryCount; + var memoryCount = Marshal.ReadInt32(pStr); + uint memoryVal = (uint)memoryCount; - if (memoryCount < 0) - { - memoryVal = (uint)((uint)int.MaxValue + (-memoryCount)); - } + if (memoryCount < 0) + { + memoryVal = (uint)((uint)int.MaxValue + (-memoryCount)); + } - var ret = memoryVal; + var ret = memoryVal; - // cleanup - Marshal.FreeHGlobal(pLen); - Marshal.FreeHGlobal(pStr); + // cleanup + Marshal.FreeHGlobal(pLen); + Marshal.FreeHGlobal(pStr); - return ret; - } + return ret; + } - private static string GetStringSysCtl(string propertyName) - { - // get the length of the string that will be returned - var pLen = Marshal.AllocHGlobal(sizeof(int)); - sysctlbyname(propertyName, IntPtr.Zero, pLen, IntPtr.Zero, 0); + private static string GetStringSysCtl(string propertyName) + { + // get the length of the string that will be returned + var pLen = Marshal.AllocHGlobal(sizeof(int)); + sysctlbyname(propertyName, IntPtr.Zero, pLen, IntPtr.Zero, 0); - var length = Marshal.ReadInt32(pLen); + var length = Marshal.ReadInt32(pLen); - // check to see if we got a length - if (length <= 0) - { - Marshal.FreeHGlobal(pLen); - return "Unknown"; - } + // check to see if we got a length + if (length <= 0) + { + Marshal.FreeHGlobal(pLen); + return "Unknown"; + } - // get the hardware string - var pStr = Marshal.AllocHGlobal(length); - sysctlbyname(propertyName, pStr, pLen, IntPtr.Zero, 0); + // get the hardware string + var pStr = Marshal.AllocHGlobal(length); + sysctlbyname(propertyName, pStr, pLen, IntPtr.Zero, 0); - // convert the native string into a C# integer + // convert the native string into a C# integer - var hardwareStr = Marshal.PtrToStringAnsi(pStr); + var hardwareStr = Marshal.PtrToStringAnsi(pStr); - // cleanup - Marshal.FreeHGlobal(pLen); - Marshal.FreeHGlobal(pStr); + // cleanup + Marshal.FreeHGlobal(pLen); + Marshal.FreeHGlobal(pStr); - return hardwareStr; - } -#endif + return hardwareStr; + } +#elif WINDOWS + private static GCMemoryInfo gcMemoryInfo = GC.GetGCMemoryInfo(); +#endif public static string Model() { #if WINDOWS @@ -97,7 +101,7 @@ public static string Model() #elif ANDROID return DeviceInfo.Current.Model; #elif IOS || MACCATALYST -return GetStringSysCtl(MACHINE_PROP_NAME); + return GetStringSysCtl(MACHINE_PROP_NAME); #else return "unknown"; #endif @@ -106,7 +110,7 @@ public static string Model() public static ulong TotalPhysicalMemory() { #if WINDOWS - return 0; + return (ulong)(gcMemoryInfo.TotalAvailableMemoryBytes); //This gives the total system memory, which is a different number to what the mobile API's are reporting. #elif ANDROID var runtime = Java.Lang.Runtime.GetRuntime(); if (runtime != null) @@ -128,7 +132,8 @@ public static ulong TotalPhysicalMemory() public static ulong AvailablePhysicalMemory() { #if WINDOWS - return 0; + Process p = Process.GetCurrentProcess(); + return (ulong)p.PrivateMemorySize64; //Not sure if this is the right value to use #elif ANDROID var runtime = Java.Lang.Runtime.GetRuntime(); if (runtime != null) @@ -153,7 +158,7 @@ public static string Platform() #elif ANDROID return "Android"; #elif IOS - return "iOS"; + return "iOS"; #elif MACCATALYST return "MacCatalyst"; #else @@ -161,15 +166,6 @@ public static string Platform() #endif } - public static string MachineName() - { -#if IOS - return UIDevice.CurrentDevice.Name; -#else - return DeviceInfo.Current.Name; -#endif - } - public static string Architecture() { #if WINDOWS @@ -186,7 +182,7 @@ public static string Architecture() } #elif IOS - return RuntimeInformation.ProcessArchitecture.ToString(); + return RuntimeInformation.ProcessArchitecture.ToString(); #elif MACCATALYST return RuntimeInformation.ProcessArchitecture.ToString(); #else diff --git a/Raygun4Maui/RaygunClient.cs b/Raygun4Maui/RaygunClient.cs index fc2ce1d..88f58f4 100644 --- a/Raygun4Maui/RaygunClient.cs +++ b/Raygun4Maui/RaygunClient.cs @@ -46,7 +46,7 @@ protected override async Task BuildMessage(Exception exception, I var details = new RaygunMessageDetails { - MachineName = NativeDeviceInfo.MachineName(), + MachineName = DeviceInfo.Current.Name, Client = ClientMessage, Error = RaygunErrorMessageBuilder.Build(exception), UserCustomData = userCustomData, From a03b4bbe3c0bc1f83314473e9cb82d74c066d32e Mon Sep 17 00:00:00 2001 From: hamish taylor Date: Tue, 9 May 2023 16:28:49 +1200 Subject: [PATCH 10/23] Added section to read me about device names on iOS. --- README.md | 3 +++ Raygun4Maui/raygun4maui.csproj | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a105249..06dfb19 100644 --- a/README.md +++ b/README.md @@ -130,7 +130,10 @@ try { ``` --- +## Platform specific information +Raygun4Maui will automatically collect information specific to the environment the application is being run in. However, on iOS, Raygun4Maui cannot obtain the devices name. This is a privacy restriction put in place by Apple. If you would like this information to be collected and sent with crash reports you will have to [request for permission from apple](https://developer.apple.com/documentation/bundleresources/entitlements/com_apple_developer_device-information_user-assigned-device-name?language=objc). +--- ## Development Instructions ### To build a local nuget package diff --git a/Raygun4Maui/raygun4maui.csproj b/Raygun4Maui/raygun4maui.csproj index fddd566..42f73eb 100644 --- a/Raygun4Maui/raygun4maui.csproj +++ b/Raygun4Maui/raygun4maui.csproj @@ -16,7 +16,7 @@ 10.0.17763.0 6.5 True - 1.2.0 + 1.2.1 Raygun Raygun README.md From 9751f2c7d2524957bd768ca1a8d74e6c61130fff Mon Sep 17 00:00:00 2001 From: hamish taylor Date: Wed, 10 May 2023 12:42:07 +1200 Subject: [PATCH 11/23] Added conversions of apple device codes to model names. --- Raygun4Maui.SampleApp/MauiProgram.cs | 1 - Raygun4Maui/NativeDeviceInfo.cs | 291 ++++++++++++++++++++++++++- Raygun4Maui/RaygunClient.cs | 2 +- 3 files changed, 290 insertions(+), 4 deletions(-) diff --git a/Raygun4Maui.SampleApp/MauiProgram.cs b/Raygun4Maui.SampleApp/MauiProgram.cs index b4504ec..fc0c195 100644 --- a/Raygun4Maui.SampleApp/MauiProgram.cs +++ b/Raygun4Maui.SampleApp/MauiProgram.cs @@ -1,5 +1,4 @@ using Microsoft.Extensions.Configuration; -using Raygun4Maui; namespace Raygun4Maui.SampleApp; diff --git a/Raygun4Maui/NativeDeviceInfo.cs b/Raygun4Maui/NativeDeviceInfo.cs index d336e5b..2fd784d 100644 --- a/Raygun4Maui/NativeDeviceInfo.cs +++ b/Raygun4Maui/NativeDeviceInfo.cs @@ -97,11 +97,11 @@ private static string GetStringSysCtl(string propertyName) public static string Model() { #if WINDOWS -return DeviceInfo.Current.Model; + return DeviceInfo.Current.Model; #elif ANDROID return DeviceInfo.Current.Model; #elif IOS || MACCATALYST - return GetStringSysCtl(MACHINE_PROP_NAME); + return GetModel(DeviceInfo.Current.Model); #else return "unknown"; #endif @@ -189,5 +189,292 @@ public static string Architecture() return RuntimeInformation.ProcessArchitecture.ToString(); #endif } +#if IOS || MACCATALYST + public static string GetModel(string hardware) + { + if (hardware.StartsWith("iPhone")) + { + switch (hardware) + { + case "iPhone15,2": + return "iPhone 14 Pro"; + case "iPhone15,3": + return "iPhone 14 Pro Max"; + case "iPhone14,8": + return "iPhone 14 Plus"; + case "iPhone14,7": + return "iPhone 14"; + case "iPhone14,6": + return "iPhone SE (3rd generation)"; + case "iPhone14,2": + return "iPhone 13 Pro"; + case "iPhone14,3": + return "iPhone 13 Pro Max"; + case "iPhone14,4": + return "iPhone 13 mini"; + case "iPhone14,5": + return "iPhone 13"; + case "iPhone13,1": + return "iPhone 12 mini"; + case "iPhone13,2": + return "iPhone 12"; + case "iPhone13,3": + return "iPhone 12 Pro"; + case "iPhone13,4": + return "iPhone 12 Pro Max"; + case "iPhone12,8": + return "iPhone SE (2nd generation)"; + case "iPhone12,5": + return "iPhone 11 Pro Max"; + case "iPhone12,3": + return "iPhone 11 Pro"; + case "iPhone12,1": + return "iPhone 11"; + case "iPhone11,2": + return "iPhone XS"; + case "iPhone11,4": + case "iPhone11,6": + return "iPhone XS Max"; + case "iPhone11,8": + return "iPhone XR"; + case "iPhone10,3": + case "iPhone10,6": + return "iPhone X"; + case "iPhone10,2": + case "iPhone10,5": + return "iPhone 8 Plus"; + case "iPhone10,1": + case "iPhone10,4": + return "iPhone 8"; + case "iPhone9,2": + case "iPhone9,4": + return "iPhone 7 Plus"; + case "iPhone9,1": + case "iPhone9,3": + return "iPhone 7"; + case "iPhone8,4": + return "iPhone SE"; + case "iPhone8,2": + return "iPhone 6S Plus"; + case "iPhone8,1": + return "iPhone 6S"; + case "iPhone7,1": + return "iPhone 6 Plus"; + case "iPhone7,2": + return "iPhone 6"; + case "iPhone6,2": + return "iPhone 5S Global"; + case "iPhone6,1": + return "iPhone 5S GSM"; + case "iPhone5,4": + return "iPhone 5C Global"; + case "iPhone5,3": + return "iPhone 5C GSM"; + case "iPhone5,2": + return "iPhone 5 Global"; + case "iPhone5,1": + return "iPhone 5 GSM"; + case "iPhone4,1": + return "iPhone 4S"; + case "iPhone3,3": + return "iPhone 4 CDMA"; + case "iPhone3,1": + case "iPhone3,2": + return "iPhone 4 GSM"; + case "iPhone2,1": + return "iPhone 3GS"; + case "iPhone1,2": + return "iPhone 3G"; + case "iPhone1,1": + return "iPhone"; + } + } + + if (hardware.StartsWith("iPod")) + { + switch (hardware) + { + case "iPod9,1": + return "iPod touch 7G"; + case "iPod7,1": + return "iPod touch 6G"; + case "iPod5,1": + return "iPod touch 5G"; + case "iPod4,1": + return "iPod touch 4G"; + case "iPod3,1": + return "iPod touch 3G"; + case "iPod2,1": + return "iPod touch 2G"; + case "iPod1,1": + return "iPod touch"; + } + } + + if (hardware.StartsWith("iPad")) + { + switch (hardware) + { + case "iPad14,2": + return "iPad mini (6th generation) Wi-FI + Cellular"; + case "iPad14,1": + return "iPad mini (6th generation) Wi-FI"; + case "iPad13,17": + case "iPad13,16": + return "iPad Air 5"; + case "iPad13,11": + return "iPad Pro (12.9-inch) (5th generation) Wi-Fi + Cellular"; + case "iPad13,10": + return "iPad Pro (12.9-inch) (5th generation) Wi-Fi + Cellular"; + case "iPad13,9": + return "iPad Pro (12.9-inch) (5th generation) Wi-Fi"; + case "iPad13,8": + return "iPad Pro (12.9-inch) (5th generation) Wi-Fi"; + case "iPad13,7": + return "iPad Pro (11-inch) (3rd generation) Wi-Fi + Cellular"; + case "iPad13,6": + return "iPad Pro (11-inch) (3rd generation) Wi-Fi + Cellular"; + case "iPad13,5": + return "iPad Pro (11-inch) (3rd generation) Wi-Fi"; + case "iPad13,4": + return "iPad Pro (11-inch) (3rd generation) Wi-Fi"; + case "iPad13,2": + return "iPad Air (4th generation) Wi-Fi + Cellular"; + case "iPad13,1": + return "iPad Air (4th generation) Wi-Fi"; + case "iPad12,2": + return "iPad (9th Generation) Wi-Fi + Cellular"; + case "iPad12,1": + return "iPad (9th generation) Wi-Fi"; + case "iPad11,7": + return "iPad (8th Generation) Wi-Fi + Cellular"; + case "iPad11,6": + return "iPad (8th Generation) Wi-Fi"; + case "iPad11,4": + return "iPad Air (3rd generation) Wi-Fi + Cellular"; + case "iPad11,3": + return "iPad Air (3rd generation) Wi-Fi"; + case "iPad11,2": + return "iPad mini (5th generation) Wi-Fi + Cellular"; + case "iPad11,1": + return "iPad mini (5th generation) Wi-Fi"; + case "iPad8,12": + return "iPad Pro (12.9-inch) (4th generation) Wi-Fi + Cellular"; + case "iPad8,11": + return "iPad Pro (12.9-inch) (4th generation) Wi-Fi"; + case "iPad8,10": + return "iPad Pro (11-inch) (2nd generation) Wi-Fi + Cellular"; + case "iPad8,9": + return "iPad Pro (11-inch) (2nd generation) Wi-Fi"; + case "iPad8,8": + return "iPad Pro 12.9-inch (3rd Generation)"; + case "iPad8,7": + return "iPad Pro 12.9-inch (3rd generation) Wi-Fi + Cellular"; + case "iPad8,6": + return "iPad Pro 12.9-inch (3rd Generation)"; + case "iPad8,5": + return "iPad Pro 12.9-inch (3rd Generation)"; + case "iPad8,4": + return "iPad Pro 11-inch"; + case "iPad8,3": + return "iPad Pro 11-inch Wi-Fi + Cellular"; + case "iPad8,2": + return "iPad Pro 11-inch"; + case "iPad8,1": + return "iPad Pro 11-inch Wi-Fi"; + case "iPad7,12": + return "iPad (7th generation) Wi-Fi + Cellular"; + case "iPad7,11": + return "iPad (7th generation) Wi-Fi"; + case "iPad7,6": + return "iPad (6th generation) Wi-Fi + Cellular"; + case "iPad7,5": + return "iPad (6th generation) Wi-Fi"; + case "iPad7,4": + return "iPad Pro (10.5-inch) Wi-Fi + Cellular"; + case "iPad7,3": + return "iPad Pro (10.5-inch) Wi-Fi"; + case "iPad7,2": + return "iPad Pro 12.9-inch (2nd generation) Wi-Fi + Cellular"; + case "iPad7,1": + return "iPad Pro 12.9-inch (2nd generation) Wi-Fi"; + case "iPad6,12": + return "iPad (5th generation) Wi-Fi + Cellular"; + case "iPad6,11": + return "iPad (5th generation) Wi-Fi"; + case "iPad6,8": + return "iPad Pro 12.9-inch Wi-Fi + Cellular"; + case "iPad6,7": + return "iPad Pro 12.9-inch Wi-Fi"; + case "iPad6,4": + return "iPad Pro (9.7-inch) Wi-Fi + Cellular"; + case "iPad6,3": + return "iPad Pro (9.7-inch) Wi-Fi"; + case "iPad5,4": + return "iPad Air 2 Wi-Fi + Cellular"; + case "iPad5,3": + return "iPad Air 2 Wi-Fi"; + case "iPad5,2": + return "iPad mini 4 Wi-Fi + Cellular"; + case "iPad5,1": + return "iPad mini 4 Wi-Fi"; + case "iPad4,9": + return "iPad mini 3 Wi-Fi + Cellular (TD-LTE)"; + case "iPad4,8": + return "iPad mini 3 Wi-Fi + Cellular"; + case "iPad4,7": + return "iPad mini 3 Wi-Fi"; + case "iPad4,6": + return "iPad mini 2 Wi-Fi + Cellular (TD-LTE)"; + case "iPad4,5": + return "iPad mini 2 Wi-Fi + Cellular"; + case "iPad4,4": + return "iPad mini 2 Wi-Fi"; + case "iPad4,3": + return "iPad Air Wi-Fi + Cellular (TD-LTE)"; + case "iPad4,2": + return "iPad Air Wi-Fi + Cellular"; + case "iPad4,1": + return "iPad Air Wi-Fi"; + case "iPad3,6": + return "iPad (4th generation) Wi-Fi + Cellular (MM)"; + case "iPad3,5": + return "iPad (4th generation) Wi-Fi + Cellular"; + case "iPad3,4": + return "iPad (4th generation) Wi-Fi"; + case "iPad3,3": + return "iPad 3 Wi-Fi + Cellular (CDMA)"; + case "iPad3,2": + return "iPad 3 Wi-Fi + Cellular (GSM)"; + case "iPad3,1": + return "iPad 3 Wi-Fi"; + case "iPad2,7": + return "iPad mini Wi-Fi + Cellular (MM)"; + case "iPad2,6": + return "iPad mini Wi-Fi + Cellular"; + case "iPad2,5": + return "iPad mini Wi-Fi"; + case "iPad2,4": + return "iPad 2 Wi-Fi"; + case "iPad2,3": + return "iPad 2 CDMA"; + case "iPad2,2": + return "iPad 2 GSM"; + case "iPad2,1": + return "iPad 2 Wi-Fi"; + case "iPad1,1": + return "iPad"; + } + } + + if (hardware == "i386" || hardware == "x86_64") + return DeviceInfo.Current.Name + " (Simulator)"; + + if (hardware == "mac") + return "Mac"; + + return (hardware == "" ? "Unknown" : hardware); + } +#endif } } diff --git a/Raygun4Maui/RaygunClient.cs b/Raygun4Maui/RaygunClient.cs index 88f58f4..0c6b1f6 100644 --- a/Raygun4Maui/RaygunClient.cs +++ b/Raygun4Maui/RaygunClient.cs @@ -36,7 +36,7 @@ protected override async Task BuildMessage(Exception exception, I WindowBoundsHeight = DeviceDisplay.MainDisplayInfo.Height, DeviceManufacturer = DeviceInfo.Current.Manufacturer, Platform = NativeDeviceInfo.Platform(), - Model = DeviceInfo.Current.Model, + Model = NativeDeviceInfo.Model(), ProcessorCount = Environment.ProcessorCount, ResolutionScale = DeviceDisplay.MainDisplayInfo.Density, TotalPhysicalMemory = NativeDeviceInfo.TotalPhysicalMemory(), From d26ae3a3dce0df633a3c8158fc1d3bced9da4ae6 Mon Sep 17 00:00:00 2001 From: hamish taylor Date: Wed, 10 May 2023 12:44:59 +1200 Subject: [PATCH 12/23] Added source --- Raygun4Maui/NativeDeviceInfo.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Raygun4Maui/NativeDeviceInfo.cs b/Raygun4Maui/NativeDeviceInfo.cs index 2fd784d..5e4887c 100644 --- a/Raygun4Maui/NativeDeviceInfo.cs +++ b/Raygun4Maui/NativeDeviceInfo.cs @@ -190,6 +190,7 @@ public static string Architecture() #endif } #if IOS || MACCATALYST + //Code from https://github.com/dannycabrera/Get-iOS-Model public static string GetModel(string hardware) { if (hardware.StartsWith("iPhone")) From 4c2c4df7e04ee35528cfea23cc608cc3205d035f Mon Sep 17 00:00:00 2001 From: hamish taylor Date: Wed, 10 May 2023 12:47:54 +1200 Subject: [PATCH 13/23] Minor spelling/grammar changes --- README.md | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 06dfb19..c8ae966 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Raygun's Crash Reporting provider for .NET MAUI ### Step 1 - Install Raygun4Maui -#### Nuget Package manager +#### NuGet Package manager The best way to install Raygun is to use the NuGet package manager. Right-click on your project and select "**Manage NuGet Packages....**". Navigate to the Browse tab, then use the search box to find **Raygun4Maui** and install it. #### .NET Cli @@ -16,7 +16,7 @@ To install the latest version: dotnet add package Raygun4Maui ``` -Alternatively you can specify a version tag to install a specific version of the package, see [Raygun4Maui NuGet Gallery page](https://nuget.org/packages/Raygun4Maui) for information of versions. +Alternatively, you can specify a version tag to install a specific version of the package. See [Raygun4Maui NuGet Gallery page](https://nuget.org/packages/Raygun4Maui) for information on available versions. ``` dotnet add package Raygun4Maui --version 1.2.0 ``` @@ -54,10 +54,10 @@ To use these additional configurations, create and initialize a new `RaygunMauiS ``` csharp Raygun4MauiSettings raygunMauiSettings = new Raygun4MauiSettings { ApiKey = "paste_your_api_key_here", - SendDefaultTags = true, // Default value - SendDefaultCustomData = true, // Default value - MinLogLevel = LogLevel.Debug, // Default value - MaxLogLevel = LogLevel.Critical // Default value + SendDefaultTags = true, // defaults to true + SendDefaultCustomData = true, // defaults to true + MinLogLevel = LogLevel.Debug, // defaults to true + MaxLogLevel = LogLevel.Critical // defaults to true }; ``` @@ -101,26 +101,26 @@ try { An exception needs to be thrown in order for its stack trace to be populated. If the exception is created manually no stack trace data is collected. ### Other examples -For aditional examples on how to use the `RaygunClient` object refer to the [Raygun4Net.NetCore documentation](https://raygun.com/documentation/language-guides/dotnet/crash-reporting/net-core/) +For additional examples on how to use the `RaygunClient` object refer to the [Raygun4Net.NetCore documentation](https://raygun.com/documentation/language-guides/dotnet/crash-reporting/net-core/) ## ILogger logging Raygun4Maui will automatically send any logger logs to Raygun. To make a log entry, obtain the reference to the ILogger services that your MAUI app maintains: -``` c# +``` csharp ILogger logger = Handler.MauiContext.Services.GetService>(); ``` -You may now invoke the various ILogger log methods from the logger object accordingly. This uses the same `RaygunClient` object accessible from `RaygunMauiClient.Current` +You may now use the appropriate ILogger log method from the logger object. This uses the same `RaygunClient` object accessible from `RaygunMauiClient.Current` -```c# +```csharp logger.LogInformation("Raygun4Maui.SampleApp.TestLoggerErrorsSent: {MethodName} @ {Timestamp}", "TestLogInformation", DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss")); logger.LogCritical("Raygun4Maui.SampleApp.TestLoggerErrorsSent: {MethodName} @ {Timestamp}", "TestLogCritical", DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss")); ``` -With this functionality, you can also manually catch-and-log exceptions as follows: +This functionality also allows you to manually catch and log exceptions as shown below: -``` c# +``` csharp try { // Code that throws exception } catch (Exception e) { From cc9db0da820fca88b599c143717274763ac7584c Mon Sep 17 00:00:00 2001 From: hamish taylor Date: Wed, 10 May 2023 12:48:43 +1200 Subject: [PATCH 14/23] Changed version number in nuget install instruction --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c8ae966..87d3e5a 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ dotnet add package Raygun4Maui Alternatively, you can specify a version tag to install a specific version of the package. See [Raygun4Maui NuGet Gallery page](https://nuget.org/packages/Raygun4Maui) for information on available versions. ``` -dotnet add package Raygun4Maui --version 1.2.0 +dotnet add package Raygun4Maui --version 1.2.1 ``` ### Step 2 - Add Raygun4Maui to your MauiApp builder From bfa5bb170a9c2b887c23d0de68ca8aff12e51e48 Mon Sep 17 00:00:00 2001 From: hamish taylor Date: Wed, 10 May 2023 14:00:14 +1200 Subject: [PATCH 15/23] Removed some un-nessesary imports --- Raygun4Maui/RaygunMauiEnvironmentMessage.cs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Raygun4Maui/RaygunMauiEnvironmentMessage.cs b/Raygun4Maui/RaygunMauiEnvironmentMessage.cs index b50ab07..0f963ca 100644 --- a/Raygun4Maui/RaygunMauiEnvironmentMessage.cs +++ b/Raygun4Maui/RaygunMauiEnvironmentMessage.cs @@ -1,9 +1,4 @@ using Mindscape.Raygun4Net; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Raygun4Maui { From e40d353658b1d9384cb4e747d6435a69dc2d7a07 Mon Sep 17 00:00:00 2001 From: hamish taylor Date: Wed, 10 May 2023 16:02:38 +1200 Subject: [PATCH 16/23] Removed device id conversion as this is done on the frontend --- Raygun4Maui/NativeDeviceInfo.cs | 300 -------------------------------- Raygun4Maui/RaygunClient.cs | 2 +- 2 files changed, 1 insertion(+), 301 deletions(-) diff --git a/Raygun4Maui/NativeDeviceInfo.cs b/Raygun4Maui/NativeDeviceInfo.cs index 5e4887c..f08ec8f 100644 --- a/Raygun4Maui/NativeDeviceInfo.cs +++ b/Raygun4Maui/NativeDeviceInfo.cs @@ -94,18 +94,6 @@ private static string GetStringSysCtl(string propertyName) #elif WINDOWS private static GCMemoryInfo gcMemoryInfo = GC.GetGCMemoryInfo(); #endif - public static string Model() - { -#if WINDOWS - return DeviceInfo.Current.Model; -#elif ANDROID -return DeviceInfo.Current.Model; -#elif IOS || MACCATALYST - return GetModel(DeviceInfo.Current.Model); -#else - return "unknown"; -#endif - } public static ulong TotalPhysicalMemory() { @@ -189,293 +177,5 @@ public static string Architecture() return RuntimeInformation.ProcessArchitecture.ToString(); #endif } -#if IOS || MACCATALYST - //Code from https://github.com/dannycabrera/Get-iOS-Model - public static string GetModel(string hardware) - { - if (hardware.StartsWith("iPhone")) - { - switch (hardware) - { - case "iPhone15,2": - return "iPhone 14 Pro"; - case "iPhone15,3": - return "iPhone 14 Pro Max"; - case "iPhone14,8": - return "iPhone 14 Plus"; - case "iPhone14,7": - return "iPhone 14"; - case "iPhone14,6": - return "iPhone SE (3rd generation)"; - case "iPhone14,2": - return "iPhone 13 Pro"; - case "iPhone14,3": - return "iPhone 13 Pro Max"; - case "iPhone14,4": - return "iPhone 13 mini"; - case "iPhone14,5": - return "iPhone 13"; - case "iPhone13,1": - return "iPhone 12 mini"; - case "iPhone13,2": - return "iPhone 12"; - case "iPhone13,3": - return "iPhone 12 Pro"; - case "iPhone13,4": - return "iPhone 12 Pro Max"; - case "iPhone12,8": - return "iPhone SE (2nd generation)"; - case "iPhone12,5": - return "iPhone 11 Pro Max"; - case "iPhone12,3": - return "iPhone 11 Pro"; - case "iPhone12,1": - return "iPhone 11"; - case "iPhone11,2": - return "iPhone XS"; - case "iPhone11,4": - case "iPhone11,6": - return "iPhone XS Max"; - case "iPhone11,8": - return "iPhone XR"; - case "iPhone10,3": - case "iPhone10,6": - return "iPhone X"; - case "iPhone10,2": - case "iPhone10,5": - return "iPhone 8 Plus"; - case "iPhone10,1": - case "iPhone10,4": - return "iPhone 8"; - case "iPhone9,2": - case "iPhone9,4": - return "iPhone 7 Plus"; - case "iPhone9,1": - case "iPhone9,3": - return "iPhone 7"; - case "iPhone8,4": - return "iPhone SE"; - case "iPhone8,2": - return "iPhone 6S Plus"; - case "iPhone8,1": - return "iPhone 6S"; - case "iPhone7,1": - return "iPhone 6 Plus"; - case "iPhone7,2": - return "iPhone 6"; - case "iPhone6,2": - return "iPhone 5S Global"; - case "iPhone6,1": - return "iPhone 5S GSM"; - case "iPhone5,4": - return "iPhone 5C Global"; - case "iPhone5,3": - return "iPhone 5C GSM"; - case "iPhone5,2": - return "iPhone 5 Global"; - case "iPhone5,1": - return "iPhone 5 GSM"; - case "iPhone4,1": - return "iPhone 4S"; - case "iPhone3,3": - return "iPhone 4 CDMA"; - case "iPhone3,1": - case "iPhone3,2": - return "iPhone 4 GSM"; - case "iPhone2,1": - return "iPhone 3GS"; - case "iPhone1,2": - return "iPhone 3G"; - case "iPhone1,1": - return "iPhone"; - } - } - - if (hardware.StartsWith("iPod")) - { - switch (hardware) - { - case "iPod9,1": - return "iPod touch 7G"; - case "iPod7,1": - return "iPod touch 6G"; - case "iPod5,1": - return "iPod touch 5G"; - case "iPod4,1": - return "iPod touch 4G"; - case "iPod3,1": - return "iPod touch 3G"; - case "iPod2,1": - return "iPod touch 2G"; - case "iPod1,1": - return "iPod touch"; - } - } - - if (hardware.StartsWith("iPad")) - { - switch (hardware) - { - case "iPad14,2": - return "iPad mini (6th generation) Wi-FI + Cellular"; - case "iPad14,1": - return "iPad mini (6th generation) Wi-FI"; - case "iPad13,17": - case "iPad13,16": - return "iPad Air 5"; - case "iPad13,11": - return "iPad Pro (12.9-inch) (5th generation) Wi-Fi + Cellular"; - case "iPad13,10": - return "iPad Pro (12.9-inch) (5th generation) Wi-Fi + Cellular"; - case "iPad13,9": - return "iPad Pro (12.9-inch) (5th generation) Wi-Fi"; - case "iPad13,8": - return "iPad Pro (12.9-inch) (5th generation) Wi-Fi"; - case "iPad13,7": - return "iPad Pro (11-inch) (3rd generation) Wi-Fi + Cellular"; - case "iPad13,6": - return "iPad Pro (11-inch) (3rd generation) Wi-Fi + Cellular"; - case "iPad13,5": - return "iPad Pro (11-inch) (3rd generation) Wi-Fi"; - case "iPad13,4": - return "iPad Pro (11-inch) (3rd generation) Wi-Fi"; - case "iPad13,2": - return "iPad Air (4th generation) Wi-Fi + Cellular"; - case "iPad13,1": - return "iPad Air (4th generation) Wi-Fi"; - case "iPad12,2": - return "iPad (9th Generation) Wi-Fi + Cellular"; - case "iPad12,1": - return "iPad (9th generation) Wi-Fi"; - case "iPad11,7": - return "iPad (8th Generation) Wi-Fi + Cellular"; - case "iPad11,6": - return "iPad (8th Generation) Wi-Fi"; - case "iPad11,4": - return "iPad Air (3rd generation) Wi-Fi + Cellular"; - case "iPad11,3": - return "iPad Air (3rd generation) Wi-Fi"; - case "iPad11,2": - return "iPad mini (5th generation) Wi-Fi + Cellular"; - case "iPad11,1": - return "iPad mini (5th generation) Wi-Fi"; - case "iPad8,12": - return "iPad Pro (12.9-inch) (4th generation) Wi-Fi + Cellular"; - case "iPad8,11": - return "iPad Pro (12.9-inch) (4th generation) Wi-Fi"; - case "iPad8,10": - return "iPad Pro (11-inch) (2nd generation) Wi-Fi + Cellular"; - case "iPad8,9": - return "iPad Pro (11-inch) (2nd generation) Wi-Fi"; - case "iPad8,8": - return "iPad Pro 12.9-inch (3rd Generation)"; - case "iPad8,7": - return "iPad Pro 12.9-inch (3rd generation) Wi-Fi + Cellular"; - case "iPad8,6": - return "iPad Pro 12.9-inch (3rd Generation)"; - case "iPad8,5": - return "iPad Pro 12.9-inch (3rd Generation)"; - case "iPad8,4": - return "iPad Pro 11-inch"; - case "iPad8,3": - return "iPad Pro 11-inch Wi-Fi + Cellular"; - case "iPad8,2": - return "iPad Pro 11-inch"; - case "iPad8,1": - return "iPad Pro 11-inch Wi-Fi"; - case "iPad7,12": - return "iPad (7th generation) Wi-Fi + Cellular"; - case "iPad7,11": - return "iPad (7th generation) Wi-Fi"; - case "iPad7,6": - return "iPad (6th generation) Wi-Fi + Cellular"; - case "iPad7,5": - return "iPad (6th generation) Wi-Fi"; - case "iPad7,4": - return "iPad Pro (10.5-inch) Wi-Fi + Cellular"; - case "iPad7,3": - return "iPad Pro (10.5-inch) Wi-Fi"; - case "iPad7,2": - return "iPad Pro 12.9-inch (2nd generation) Wi-Fi + Cellular"; - case "iPad7,1": - return "iPad Pro 12.9-inch (2nd generation) Wi-Fi"; - case "iPad6,12": - return "iPad (5th generation) Wi-Fi + Cellular"; - case "iPad6,11": - return "iPad (5th generation) Wi-Fi"; - case "iPad6,8": - return "iPad Pro 12.9-inch Wi-Fi + Cellular"; - case "iPad6,7": - return "iPad Pro 12.9-inch Wi-Fi"; - case "iPad6,4": - return "iPad Pro (9.7-inch) Wi-Fi + Cellular"; - case "iPad6,3": - return "iPad Pro (9.7-inch) Wi-Fi"; - case "iPad5,4": - return "iPad Air 2 Wi-Fi + Cellular"; - case "iPad5,3": - return "iPad Air 2 Wi-Fi"; - case "iPad5,2": - return "iPad mini 4 Wi-Fi + Cellular"; - case "iPad5,1": - return "iPad mini 4 Wi-Fi"; - case "iPad4,9": - return "iPad mini 3 Wi-Fi + Cellular (TD-LTE)"; - case "iPad4,8": - return "iPad mini 3 Wi-Fi + Cellular"; - case "iPad4,7": - return "iPad mini 3 Wi-Fi"; - case "iPad4,6": - return "iPad mini 2 Wi-Fi + Cellular (TD-LTE)"; - case "iPad4,5": - return "iPad mini 2 Wi-Fi + Cellular"; - case "iPad4,4": - return "iPad mini 2 Wi-Fi"; - case "iPad4,3": - return "iPad Air Wi-Fi + Cellular (TD-LTE)"; - case "iPad4,2": - return "iPad Air Wi-Fi + Cellular"; - case "iPad4,1": - return "iPad Air Wi-Fi"; - case "iPad3,6": - return "iPad (4th generation) Wi-Fi + Cellular (MM)"; - case "iPad3,5": - return "iPad (4th generation) Wi-Fi + Cellular"; - case "iPad3,4": - return "iPad (4th generation) Wi-Fi"; - case "iPad3,3": - return "iPad 3 Wi-Fi + Cellular (CDMA)"; - case "iPad3,2": - return "iPad 3 Wi-Fi + Cellular (GSM)"; - case "iPad3,1": - return "iPad 3 Wi-Fi"; - case "iPad2,7": - return "iPad mini Wi-Fi + Cellular (MM)"; - case "iPad2,6": - return "iPad mini Wi-Fi + Cellular"; - case "iPad2,5": - return "iPad mini Wi-Fi"; - case "iPad2,4": - return "iPad 2 Wi-Fi"; - case "iPad2,3": - return "iPad 2 CDMA"; - case "iPad2,2": - return "iPad 2 GSM"; - case "iPad2,1": - return "iPad 2 Wi-Fi"; - case "iPad1,1": - return "iPad"; - } - } - - if (hardware == "i386" || hardware == "x86_64") - return DeviceInfo.Current.Name + " (Simulator)"; - - if (hardware == "mac") - return "Mac"; - - return (hardware == "" ? "Unknown" : hardware); - } -#endif } } diff --git a/Raygun4Maui/RaygunClient.cs b/Raygun4Maui/RaygunClient.cs index 0c6b1f6..88f58f4 100644 --- a/Raygun4Maui/RaygunClient.cs +++ b/Raygun4Maui/RaygunClient.cs @@ -36,7 +36,7 @@ protected override async Task BuildMessage(Exception exception, I WindowBoundsHeight = DeviceDisplay.MainDisplayInfo.Height, DeviceManufacturer = DeviceInfo.Current.Manufacturer, Platform = NativeDeviceInfo.Platform(), - Model = NativeDeviceInfo.Model(), + Model = DeviceInfo.Current.Model, ProcessorCount = Environment.ProcessorCount, ResolutionScale = DeviceDisplay.MainDisplayInfo.Density, TotalPhysicalMemory = NativeDeviceInfo.TotalPhysicalMemory(), From 152501cfe66f05d1aedc5e0b29da4d43ec0d5f6c Mon Sep 17 00:00:00 2001 From: hamish taylor Date: Wed, 10 May 2023 16:22:52 +1200 Subject: [PATCH 17/23] merged RaygunClient into RaygunMauiClient --- README.md | 6 +-- Raygun4Maui/RaygunClient.cs | 75 --------------------------------- Raygun4Maui/RaygunMauiClient.cs | 69 ++++++++++++++++++++++++++++-- 3 files changed, 69 insertions(+), 81 deletions(-) delete mode 100644 Raygun4Maui/RaygunClient.cs diff --git a/README.md b/README.md index 87d3e5a..a47d4a7 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,7 @@ builder Unhandled exceptions will be sent to Raygun automatically. -Raygun4Maui stores an instance of a `RaygunClient` object, this can be accessed through the following code: +Raygun4Maui stores an instance of a `RaygunMauiClient` object that is initialised by the Maui builder, this can be accessed through the following code: ``` csharp RaygunMauiClient.Current ``` @@ -101,7 +101,7 @@ try { An exception needs to be thrown in order for its stack trace to be populated. If the exception is created manually no stack trace data is collected. ### Other examples -For additional examples on how to use the `RaygunClient` object refer to the [Raygun4Net.NetCore documentation](https://raygun.com/documentation/language-guides/dotnet/crash-reporting/net-core/) +For additional examples on how to use the `RaygunMauiClient` object refer to the [Raygun4Net.NetCore documentation](https://raygun.com/documentation/language-guides/dotnet/crash-reporting/net-core/) ## ILogger logging Raygun4Maui will automatically send any logger logs to Raygun. @@ -111,7 +111,7 @@ To make a log entry, obtain the reference to the ILogger services that your MAUI ILogger logger = Handler.MauiContext.Services.GetService>(); ``` -You may now use the appropriate ILogger log method from the logger object. This uses the same `RaygunClient` object accessible from `RaygunMauiClient.Current` +You may now use the appropriate ILogger log method from the logger object. This uses the same `RaygunMauiClient` object accessible from `RaygunMauiClient.Current` ```csharp logger.LogInformation("Raygun4Maui.SampleApp.TestLoggerErrorsSent: {MethodName} @ {Timestamp}", "TestLogInformation", DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss")); diff --git a/Raygun4Maui/RaygunClient.cs b/Raygun4Maui/RaygunClient.cs deleted file mode 100644 index 88f58f4..0000000 --- a/Raygun4Maui/RaygunClient.cs +++ /dev/null @@ -1,75 +0,0 @@ -using Mindscape.Raygun4Net; -using System.Collections; -using System.Globalization; -using System.Reflection; - -namespace Raygun4Maui -{ - public class RaygunClient : Mindscape.Raygun4Net.RaygunClient - { - public RaygunClient(string apiKey) : base(apiKey) - { - } - - public RaygunClient(RaygunSettings settings) : base(settings) - { - } - - public static readonly RaygunClientMessage ClientMessage = new() - { - Name = "Raygun4Maui", - Version = Assembly.GetExecutingAssembly().GetName().Version.ToString(), - ClientUrl = "https://github.com/MindscapeHQ/raygun4maui" - }; - - - protected override async Task BuildMessage(Exception exception, IList tags, IDictionary userCustomData, RaygunIdentifierMessage userInfo) - { - DateTime now = DateTime.Now; - var environment = new RaygunMauiEnvironmentMessage //Mostlikely should be static - { - UtcOffset = TimeZoneInfo.Local.GetUtcOffset(now).TotalHours, - Locale = CultureInfo.CurrentCulture.DisplayName, - OSVersion = DeviceInfo.Current.VersionString, - Architecture = NativeDeviceInfo.Architecture(), - WindowBoundsWidth = DeviceDisplay.MainDisplayInfo.Width, - WindowBoundsHeight = DeviceDisplay.MainDisplayInfo.Height, - DeviceManufacturer = DeviceInfo.Current.Manufacturer, - Platform = NativeDeviceInfo.Platform(), - Model = DeviceInfo.Current.Model, - ProcessorCount = Environment.ProcessorCount, - ResolutionScale = DeviceDisplay.MainDisplayInfo.Density, - TotalPhysicalMemory = NativeDeviceInfo.TotalPhysicalMemory(), - AvailablePhysicalMemory = NativeDeviceInfo.AvailablePhysicalMemory(), - CurrentOrientation = DeviceDisplay.MainDisplayInfo.Orientation.ToString(), - }; - - var details = new RaygunMessageDetails - { - MachineName = DeviceInfo.Current.Name, - Client = ClientMessage, - Error = RaygunErrorMessageBuilder.Build(exception), - UserCustomData = userCustomData, - Tags = tags, - Version = ApplicationVersion, - User = userInfo ?? UserInfo ?? (!String.IsNullOrEmpty(User) ? new RaygunIdentifierMessage(User) : null), - Environment = environment - }; - - var message = new RaygunMessage - { - OccurredOn = DateTime.UtcNow, - Details = details - }; - - var customGroupingKey = await OnCustomGroupingKey(exception, message).ConfigureAwait(false); - - if (string.IsNullOrEmpty(customGroupingKey) == false) - { - message.Details.GroupingKey = customGroupingKey; - } - - return message; - } - } -} diff --git a/Raygun4Maui/RaygunMauiClient.cs b/Raygun4Maui/RaygunMauiClient.cs index 93d3439..857828d 100644 --- a/Raygun4Maui/RaygunMauiClient.cs +++ b/Raygun4Maui/RaygunMauiClient.cs @@ -6,6 +6,8 @@ using System.Runtime.CompilerServices; using Microsoft.Maui.Platform; using Microsoft.Maui.Devices; +using Windows.System; +using System.Collections; #if ANDROID using Android.App; using Android.Content; @@ -14,11 +16,10 @@ namespace Raygun4Maui { - public static class RaygunMauiClient + public class RaygunMauiClient : RaygunClient { private static RaygunClient _instance; public static RaygunClient Current => _instance; - internal static void Attach(RaygunClient client) { if (_instance != null) @@ -27,8 +28,70 @@ internal static void Attach(RaygunClient client) } _instance = client; + } + + public RaygunMauiClient(string apiKey) : base(apiKey) + { + } + + public RaygunMauiClient(RaygunSettings settings) : base(settings) + { + } - } + public static readonly RaygunClientMessage clientMessage = new() + { + Name = "Raygun4Maui", + Version = Assembly.GetExecutingAssembly().GetName().Version.ToString(), + ClientUrl = "https://github.com/MindscapeHQ/raygun4maui" + }; + + protected override async Task BuildMessage(Exception exception, IList tags, IDictionary userCustomData, RaygunIdentifierMessage userInfo) + { + DateTime now = DateTime.Now; + var environment = new RaygunMauiEnvironmentMessage //Mostlikely should be static + { + UtcOffset = TimeZoneInfo.Local.GetUtcOffset(now).TotalHours, + Locale = CultureInfo.CurrentCulture.DisplayName, + OSVersion = DeviceInfo.Current.VersionString, + Architecture = NativeDeviceInfo.Architecture(), + WindowBoundsWidth = DeviceDisplay.MainDisplayInfo.Width, + WindowBoundsHeight = DeviceDisplay.MainDisplayInfo.Height, + DeviceManufacturer = DeviceInfo.Current.Manufacturer, + Platform = NativeDeviceInfo.Platform(), + Model = DeviceInfo.Current.Model, + ProcessorCount = Environment.ProcessorCount, + ResolutionScale = DeviceDisplay.MainDisplayInfo.Density, + TotalPhysicalMemory = NativeDeviceInfo.TotalPhysicalMemory(), + AvailablePhysicalMemory = NativeDeviceInfo.AvailablePhysicalMemory(), + CurrentOrientation = DeviceDisplay.MainDisplayInfo.Orientation.ToString(), + }; + + var details = new RaygunMessageDetails + { + MachineName = DeviceInfo.Current.Name, + Client = clientMessage, + Error = RaygunErrorMessageBuilder.Build(exception), + UserCustomData = userCustomData, + Tags = tags, + Version = ApplicationVersion, + User = userInfo ?? UserInfo ?? (!String.IsNullOrEmpty(User) ? new RaygunIdentifierMessage(User) : null), + Environment = environment + }; + + var message = new RaygunMessage + { + OccurredOn = DateTime.UtcNow, + Details = details + }; + + var customGroupingKey = await OnCustomGroupingKey(exception, message).ConfigureAwait(false); + + if (string.IsNullOrEmpty(customGroupingKey) == false) + { + message.Details.GroupingKey = customGroupingKey; + } + return message; + } } } From 57a3bcfabd300ea14bfaac7f4f16d84e34a8b2d5 Mon Sep 17 00:00:00 2001 From: hamish taylor Date: Thu, 11 May 2023 09:07:57 +1200 Subject: [PATCH 18/23] Added specific information on the memory values collected. --- README.md | 12 +++++++++++- Raygun4Maui/Raygun4MauiExtensions.cs | 2 +- Raygun4Maui/RaygunMauiClient.cs | 6 +++--- Raygun4Maui/raygun4maui.csproj | 13 ++++++++++++- 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index a47d4a7..0242b8a 100644 --- a/README.md +++ b/README.md @@ -131,7 +131,17 @@ try { --- ## Platform specific information -Raygun4Maui will automatically collect information specific to the environment the application is being run in. However, on iOS, Raygun4Maui cannot obtain the devices name. This is a privacy restriction put in place by Apple. If you would like this information to be collected and sent with crash reports you will have to [request for permission from apple](https://developer.apple.com/documentation/bundleresources/entitlements/com_apple_developer_device-information_user-assigned-device-name?language=objc). +Raygun4Maui will automatically collect information specific to the environment the application is being run in. However, there are inconsistency's between certain values across platforms. +- on iOS, Raygun4Maui cannot obtain the devices name. This is a privacy restriction put in place by Apple. If you would like this information to be collected and sent with crash reports you will have to [request for permission from apple](https://developer.apple.com/documentation/bundleresources/entitlements/com_apple_developer_device-information_user-assigned-device-name?language=objc). +- The `Total physical memory` and `Available physical memory` properties mean different things across platforms. Below is a table explaining the differences for each platform. +|Platform| Total physical memory | Available physical memory | +|-----|----|-------| +| Mac | Total installed ram | Total memory available for user-level processes | +| iOS | Total installed ram | Total memory available for user-level processes | +| Windows |Total installed ram | Total amount of private memory used by the process at the time of the measurement. For a number of reasons this might not be the actual total memory usage | +| Android |Total amount of memory that the JVM has allocated for the application | Total amount of free memory that the JVM has available for the application to use | + + --- ## Development Instructions diff --git a/Raygun4Maui/Raygun4MauiExtensions.cs b/Raygun4Maui/Raygun4MauiExtensions.cs index 0d5859c..842eb0c 100644 --- a/Raygun4Maui/Raygun4MauiExtensions.cs +++ b/Raygun4Maui/Raygun4MauiExtensions.cs @@ -10,7 +10,7 @@ public static MauiAppBuilder AddRaygun4Maui( this MauiAppBuilder mauiAppBuilder, Raygun4MauiSettings raygunMauiSettings) { - RaygunMauiClient.Attach(new RaygunClient(raygunMauiSettings)); + RaygunMauiClient.Attach(new RaygunMauiClient(raygunMauiSettings)); return mauiAppBuilder .AddRaygunUnhandledExceptionsListener(raygunMauiSettings) .AddRaygunLogger(raygunMauiSettings); diff --git a/Raygun4Maui/RaygunMauiClient.cs b/Raygun4Maui/RaygunMauiClient.cs index 857828d..14c0b8a 100644 --- a/Raygun4Maui/RaygunMauiClient.cs +++ b/Raygun4Maui/RaygunMauiClient.cs @@ -18,9 +18,9 @@ namespace Raygun4Maui { public class RaygunMauiClient : RaygunClient { - private static RaygunClient _instance; - public static RaygunClient Current => _instance; - internal static void Attach(RaygunClient client) + private static RaygunMauiClient _instance; + public static RaygunMauiClient Current => _instance; + internal static void Attach(RaygunMauiClient client) { if (_instance != null) { diff --git a/Raygun4Maui/raygun4maui.csproj b/Raygun4Maui/raygun4maui.csproj index 42f73eb..da505f9 100644 --- a/Raygun4Maui/raygun4maui.csproj +++ b/Raygun4Maui/raygun4maui.csproj @@ -25,7 +25,18 @@ https://raygun.com/platform/crash-reporting https://github.com/MindscapeHQ/raygun4maui Raygun4Maui; Raygun; Crash Reporting; MAUI; .NET; dotnet - Brought feature parity with the Raygun4net.core provider + Expanded the device information that is collected when a crash is sent to Raygun. +The new information collected is as follows: +- Available physical memory +- Total physical memory +- Processor count +- Architecture +- Device manugacture +- Model +- Current orientation +- Resolution scale +- WindowBoundsWidth +- WindowBoundsHeight Raygun4Maui LICENSE True From 33045527df8b0d058c6667326753851ff1a1a69c Mon Sep 17 00:00:00 2001 From: hamish taylor Date: Thu, 11 May 2023 09:10:59 +1200 Subject: [PATCH 19/23] Removed comment --- Raygun4Maui/NativeDeviceInfo.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Raygun4Maui/NativeDeviceInfo.cs b/Raygun4Maui/NativeDeviceInfo.cs index f08ec8f..c158037 100644 --- a/Raygun4Maui/NativeDeviceInfo.cs +++ b/Raygun4Maui/NativeDeviceInfo.cs @@ -98,7 +98,7 @@ private static string GetStringSysCtl(string propertyName) public static ulong TotalPhysicalMemory() { #if WINDOWS - return (ulong)(gcMemoryInfo.TotalAvailableMemoryBytes); //This gives the total system memory, which is a different number to what the mobile API's are reporting. + return (ulong)(gcMemoryInfo.TotalAvailableMemoryBytes); #elif ANDROID var runtime = Java.Lang.Runtime.GetRuntime(); if (runtime != null) From 3316644f8a946aacc931c4173b5b45c47f2f3b91 Mon Sep 17 00:00:00 2001 From: hamish taylor Date: Thu, 11 May 2023 10:57:49 +1200 Subject: [PATCH 20/23] Added test project --- README.md | 2 +- Raygun4Maui.Test/AppShell.xaml | 14 + Raygun4Maui.Test/AppShell.xaml.cs | 10 + Raygun4Maui.Test/MainPage.xaml | 41 ++ Raygun4Maui.Test/MainPage.xaml.cs | 24 ++ Raygun4Maui.Test/MauiProgram.cs | 19 + .../Platforms/Android/AndroidManifest.xml | 6 + .../Platforms/Android/MainActivity.cs | 11 + .../Platforms/Android/MainApplication.cs | 16 + .../Android/Resources/values/colors.xml | 6 + .../Platforms/MacCatalyst/AppDelegate.cs | 10 + .../Platforms/MacCatalyst/Info.plist | 30 ++ .../Platforms/MacCatalyst/Program.cs | 16 + Raygun4Maui.Test/Platforms/Tizen/Main.cs | 17 + .../Platforms/Tizen/tizen-manifest.xml | 15 + Raygun4Maui.Test/Platforms/Windows/App.xaml | 8 + .../Platforms/Windows/App.xaml.cs | 24 ++ .../Platforms/Windows/Package.appxmanifest | 46 ++ .../Platforms/Windows/app.manifest | 15 + Raygun4Maui.Test/Platforms/iOS/AppDelegate.cs | 10 + Raygun4Maui.Test/Platforms/iOS/Info.plist | 32 ++ Raygun4Maui.Test/Platforms/iOS/Program.cs | 16 + .../Properties/launchSettings.json | 8 + Raygun4Maui.Test/Raygun4Maui.Test.csproj | 60 +++ Raygun4Maui.Test/RaygunClientTest.cs | 60 +++ .../Resources/AppIcon/appicon.svg | 4 + .../Resources/AppIcon/appiconfg.svg | 8 + .../Resources/Fonts/OpenSans-Regular.ttf | Bin 0 -> 107140 bytes .../Resources/Fonts/OpenSans-Semibold.ttf | Bin 0 -> 111068 bytes .../Resources/Images/dotnet_bot.svg | 93 ++++ .../Resources/Raw/AboutAssets.txt | 15 + Raygun4Maui.Test/Resources/Splash/splash.svg | 8 + Raygun4Maui.Test/Resources/Styles/Colors.xaml | 44 ++ Raygun4Maui.Test/Resources/Styles/Styles.xaml | 405 ++++++++++++++++++ Raygun4Maui/NativeDeviceInfo.cs | 4 +- Raygun4Maui/RaygunMauiClient.cs | 30 +- Raygun4Maui/raygun4maui.sln | 12 +- 37 files changed, 1115 insertions(+), 24 deletions(-) create mode 100644 Raygun4Maui.Test/AppShell.xaml create mode 100644 Raygun4Maui.Test/AppShell.xaml.cs create mode 100644 Raygun4Maui.Test/MainPage.xaml create mode 100644 Raygun4Maui.Test/MainPage.xaml.cs create mode 100644 Raygun4Maui.Test/MauiProgram.cs create mode 100644 Raygun4Maui.Test/Platforms/Android/AndroidManifest.xml create mode 100644 Raygun4Maui.Test/Platforms/Android/MainActivity.cs create mode 100644 Raygun4Maui.Test/Platforms/Android/MainApplication.cs create mode 100644 Raygun4Maui.Test/Platforms/Android/Resources/values/colors.xml create mode 100644 Raygun4Maui.Test/Platforms/MacCatalyst/AppDelegate.cs create mode 100644 Raygun4Maui.Test/Platforms/MacCatalyst/Info.plist create mode 100644 Raygun4Maui.Test/Platforms/MacCatalyst/Program.cs create mode 100644 Raygun4Maui.Test/Platforms/Tizen/Main.cs create mode 100644 Raygun4Maui.Test/Platforms/Tizen/tizen-manifest.xml create mode 100644 Raygun4Maui.Test/Platforms/Windows/App.xaml create mode 100644 Raygun4Maui.Test/Platforms/Windows/App.xaml.cs create mode 100644 Raygun4Maui.Test/Platforms/Windows/Package.appxmanifest create mode 100644 Raygun4Maui.Test/Platforms/Windows/app.manifest create mode 100644 Raygun4Maui.Test/Platforms/iOS/AppDelegate.cs create mode 100644 Raygun4Maui.Test/Platforms/iOS/Info.plist create mode 100644 Raygun4Maui.Test/Platforms/iOS/Program.cs create mode 100644 Raygun4Maui.Test/Properties/launchSettings.json create mode 100644 Raygun4Maui.Test/Raygun4Maui.Test.csproj create mode 100644 Raygun4Maui.Test/RaygunClientTest.cs create mode 100644 Raygun4Maui.Test/Resources/AppIcon/appicon.svg create mode 100644 Raygun4Maui.Test/Resources/AppIcon/appiconfg.svg create mode 100644 Raygun4Maui.Test/Resources/Fonts/OpenSans-Regular.ttf create mode 100644 Raygun4Maui.Test/Resources/Fonts/OpenSans-Semibold.ttf create mode 100644 Raygun4Maui.Test/Resources/Images/dotnet_bot.svg create mode 100644 Raygun4Maui.Test/Resources/Raw/AboutAssets.txt create mode 100644 Raygun4Maui.Test/Resources/Splash/splash.svg create mode 100644 Raygun4Maui.Test/Resources/Styles/Colors.xaml create mode 100644 Raygun4Maui.Test/Resources/Styles/Styles.xaml diff --git a/README.md b/README.md index 0242b8a..e4a6196 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,7 @@ builder Unhandled exceptions will be sent to Raygun automatically. -Raygun4Maui stores an instance of a `RaygunMauiClient` object that is initialised by the Maui builder, this can be accessed through the following code: +Raygun4Maui stores an instance of a `RaygunMauiClient` object that is initialized by the Maui builder, this can be accessed through the following code: ``` csharp RaygunMauiClient.Current ``` diff --git a/Raygun4Maui.Test/AppShell.xaml b/Raygun4Maui.Test/AppShell.xaml new file mode 100644 index 0000000..53eb7cf --- /dev/null +++ b/Raygun4Maui.Test/AppShell.xaml @@ -0,0 +1,14 @@ + + + + + + diff --git a/Raygun4Maui.Test/AppShell.xaml.cs b/Raygun4Maui.Test/AppShell.xaml.cs new file mode 100644 index 0000000..78e9250 --- /dev/null +++ b/Raygun4Maui.Test/AppShell.xaml.cs @@ -0,0 +1,10 @@ +namespace Raygun4Maui.testtest +{ + public partial class AppShell : Shell + { + public AppShell() + { + InitializeComponent(); + } + } +} \ No newline at end of file diff --git a/Raygun4Maui.Test/MainPage.xaml b/Raygun4Maui.Test/MainPage.xaml new file mode 100644 index 0000000..fc4d6b9 --- /dev/null +++ b/Raygun4Maui.Test/MainPage.xaml @@ -0,0 +1,41 @@ + + + + + + + + +