diff --git a/src/InfiniFrame.BlazorWebView/InfiniFrameBlazorApp.cs b/src/InfiniFrame.BlazorWebView/InfiniFrameBlazorApp.cs index 89015a89d..2676e3ff5 100644 --- a/src/InfiniFrame.BlazorWebView/InfiniFrameBlazorApp.cs +++ b/src/InfiniFrame.BlazorWebView/InfiniFrameBlazorApp.cs @@ -1,6 +1,7 @@ // --------------------------------------------------------------------------------------------------------------------- // Imports // --------------------------------------------------------------------------------------------------------------------- +using InfiniFrame.Utilities; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; @@ -62,9 +63,6 @@ public void Run() { } } - private static bool IsNonFatalException(Exception exception) - => exception is not (OutOfMemoryException or AccessViolationException); - public async ValueTask DisposeAsync() { if (_disposed) return; @@ -87,7 +85,7 @@ public async ValueTask DisposeAsync() { break; } } - catch (Exception e) when (IsNonFatalException(e)) { + catch (Exception e) when (ExceptionsUtility.IsNonFatalException(e)) { logger?.LogError(e, "Error disposing of InfiniFrameBlazorApp"); } diff --git a/src/InfiniFrame.BlazorWebView/InfiniFrameSynchronizationContext.cs b/src/InfiniFrame.BlazorWebView/InfiniFrameSynchronizationContext.cs index 9347c2477..e1fec8cac 100644 --- a/src/InfiniFrame.BlazorWebView/InfiniFrameSynchronizationContext.cs +++ b/src/InfiniFrame.BlazorWebView/InfiniFrameSynchronizationContext.cs @@ -5,6 +5,7 @@ // Imports // --------------------------------------------------------------------------------------------------------------------- using InfiniFrame.BlazorWebView.Utils; +using InfiniFrame.Utilities; using Microsoft.Extensions.DependencyInjection; namespace InfiniFrame.BlazorWebView; @@ -45,7 +46,7 @@ public Task InvokeAsync(Action action) { catch (OperationCanceledException) { completion.SetCanceled(); } - catch (Exception exception) when (IsNonFatalException(exception)) { + catch (Exception exception) when (ExceptionsUtility.IsNonFatalException(exception)) { completion.SetException(exception); } }, completion); @@ -66,7 +67,7 @@ public Task InvokeAsync(Func asyncAction) { catch (OperationCanceledException) { completion.SetCanceled(); } - catch (Exception exception) when (IsNonFatalException(exception)) { + catch (Exception exception) when (ExceptionsUtility.IsNonFatalException(exception)) { completion.SetException(exception); } }, completion); @@ -86,7 +87,7 @@ public Task InvokeAsync(Func function) { catch (OperationCanceledException) { completion.SetCanceled(); } - catch (Exception exception) when (IsNonFatalException(exception)) { + catch (Exception exception) when (ExceptionsUtility.IsNonFatalException(exception)) { completion.SetException(exception); } }, completion); @@ -107,7 +108,7 @@ public Task InvokeAsync(Func> asyncFunction) { catch (OperationCanceledException) { completion.SetCanceled(); } - catch (Exception exception) when (IsNonFatalException(exception)) { + catch (Exception exception) when (ExceptionsUtility.IsNonFatalException(exception)) { completion.SetException(exception); } }, completion); @@ -232,7 +233,7 @@ private void ExecuteBackground(InfiniFrameSynchronizationWorkItem item) { try { ExecuteSynchronously(null, item.Callback, item.StateObject); } - catch (Exception ex) when (IsNonFatalException(ex)) { + catch (Exception ex) when (ExceptionsUtility.IsNonFatalException(ex)) { DispatchException(ex); } @@ -243,7 +244,7 @@ private void ExecuteBackground(InfiniFrameSynchronizationWorkItem item) { try { ExecutionContext.Run(item.ExecutionContext, ExecutionContextThunk, item); } - catch (Exception ex) when (IsNonFatalException(ex)) { + catch (Exception ex) when (ExceptionsUtility.IsNonFatalException(ex)) { DispatchException(ex); } } @@ -252,7 +253,4 @@ private void DispatchException(Exception ex) { UnhandledExceptionEventHandler? handler = UnhandledException; handler?.Invoke(this, new UnhandledExceptionEventArgs(ex, false)); } - - private static bool IsNonFatalException(Exception exception) - => exception is not (OutOfMemoryException or AccessViolationException); } diff --git a/src/InfiniFrame.BlazorWebView/InfiniFrameWebViewManager.cs b/src/InfiniFrame.BlazorWebView/InfiniFrameWebViewManager.cs index 9fcae0670..4aef5b334 100644 --- a/src/InfiniFrame.BlazorWebView/InfiniFrameWebViewManager.cs +++ b/src/InfiniFrame.BlazorWebView/InfiniFrameWebViewManager.cs @@ -2,6 +2,7 @@ // Imports // --------------------------------------------------------------------------------------------------------------------- using InfiniFrame.BlazorWebView.Utils; +using InfiniFrame.Utilities; using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components.Web; using Microsoft.AspNetCore.Components.WebView; @@ -224,7 +225,7 @@ private async Task MessagePump() { catch (OperationCanceledException) { LazyLogger.Value?.LogDebug("WebView message pump cancellation requested."); } - catch (Exception ex) when (IsNonFatalException(ex)) { + catch (Exception ex) when (ExceptionsUtility.IsNonFatalException(ex)) { LazyLogger.Value?.LogError(ex, "Unhandled exception in WebView message pump."); throw; } @@ -250,9 +251,6 @@ protected override async ValueTask DisposeAsyncCore() { } } - private static bool IsNonFatalException(Exception exception) - => exception is not (OutOfMemoryException or AccessViolationException); - private static string GetFallbackContentType(string localPath) { string extension = Path.GetExtension(localPath); diff --git a/src/InfiniFrame.Js/Interop/RegisterWindowCreatedUtility.cs b/src/InfiniFrame.Js/Interop/RegisterWindowCreatedUtility.cs index 458d7f335..b66e9bcec 100644 --- a/src/InfiniFrame.Js/Interop/RegisterWindowCreatedUtility.cs +++ b/src/InfiniFrame.Js/Interop/RegisterWindowCreatedUtility.cs @@ -1,6 +1,7 @@ // --------------------------------------------------------------------------------------------------------------------- // Imports // --------------------------------------------------------------------------------------------------------------------- +using InfiniFrame.Utilities; using Microsoft.Extensions.Logging; using System.Runtime.CompilerServices; @@ -76,7 +77,7 @@ IReadOnlyList registrationMessages try { allMessagesSent = await SendRegistrationsAndAckAsync(window, registrationMessages); } - catch (Exception ex) when (IsNonFatalException(ex)) { + catch (Exception ex) when (ExceptionsUtility.IsNonFatalException(ex)) { window.Logger.LogError(ex, "Unhandled error while sending window-created registration messages."); } finally { @@ -96,7 +97,4 @@ private static async Task SendRegistrationsAndAckAsync(IInfiniFrameWindow window.Logger.LogDebug("Sent '{ReadyAckMessageId}' handshake acknowledgement.", HandlerNames.WindowReadyAck); return true; } - - private static bool IsNonFatalException(Exception exception) - => exception is not (OutOfMemoryException or AccessViolationException); } diff --git a/src/InfiniFrame.Shared/FluentApi/InfiniWindowBuilderExtensions.cs b/src/InfiniFrame.Shared/FluentApi/InfiniWindowBuilderExtensions.cs index d64fc3966..720a05f4a 100644 --- a/src/InfiniFrame.Shared/FluentApi/InfiniWindowBuilderExtensions.cs +++ b/src/InfiniFrame.Shared/FluentApi/InfiniWindowBuilderExtensions.cs @@ -124,7 +124,7 @@ public static T GrantBrowserPermissions(this T builder, bool enable = true) w /// The file path to the icon. /// public static T SetIconFile(this T builder, string? iconFilePath) where T : IInfiniFrameWindowBuilder { - if (!IconFileUtilities.TryResolveIconFilePath(iconFilePath, out string? resolvedIconFilePath)) return builder; + if (!IconFileUtility.TryResolveIconFilePath(iconFilePath, out string? resolvedIconFilePath)) return builder; builder.Configuration.IconFilePath = resolvedIconFilePath; return builder; diff --git a/src/InfiniFrame.Shared/FluentApi/InfiniWindowExtensions.cs b/src/InfiniFrame.Shared/FluentApi/InfiniWindowExtensions.cs index 618b6984e..737d70953 100644 --- a/src/InfiniFrame.Shared/FluentApi/InfiniWindowExtensions.cs +++ b/src/InfiniFrame.Shared/FluentApi/InfiniWindowExtensions.cs @@ -427,7 +427,7 @@ public static T SetHeight(this T window, int height) where T : class, IInfini public static T SetIconFile(this T window, string iconFilePath) where T : class, IInfiniFrameWindow { window.Logger.LogDebug(".SetIconFile({IconFile})", iconFilePath); - if (!IconFileUtilities.TryResolveIconFilePath(iconFilePath, out string? resolvedIconFilePath)) { + if (!IconFileUtility.TryResolveIconFilePath(iconFilePath, out string? resolvedIconFilePath)) { window.Logger.LogWarning("Icon file {IconFile} does not exist or is an invalid file path.", iconFilePath); return window; } diff --git a/src/InfiniFrame.Shared/InfiniFrame.Shared.csproj b/src/InfiniFrame.Shared/InfiniFrame.Shared.csproj index 8af610c0a..3f1336e78 100644 --- a/src/InfiniFrame.Shared/InfiniFrame.Shared.csproj +++ b/src/InfiniFrame.Shared/InfiniFrame.Shared.csproj @@ -42,6 +42,7 @@ + diff --git a/src/InfiniFrame.Shared/Utilities/InfiniFrameNativeParametersValidator.cs b/src/InfiniFrame.Shared/Native/InfiniFrameNativeParametersValidator.cs similarity index 94% rename from src/InfiniFrame.Shared/Utilities/InfiniFrameNativeParametersValidator.cs rename to src/InfiniFrame.Shared/Native/InfiniFrameNativeParametersValidator.cs index 69b5d290a..f12cc4d8a 100644 --- a/src/InfiniFrame.Shared/Utilities/InfiniFrameNativeParametersValidator.cs +++ b/src/InfiniFrame.Shared/Native/InfiniFrameNativeParametersValidator.cs @@ -1,11 +1,11 @@ // --------------------------------------------------------------------------------------------------------------------- // Imports // --------------------------------------------------------------------------------------------------------------------- -using InfiniFrame.Native; +using InfiniFrame.Utilities; using Microsoft.Extensions.Logging; using System.Runtime.InteropServices; -namespace InfiniFrame.Utilities; +namespace InfiniFrame.Native; // --------------------------------------------------------------------------------------------------------------------- // Code // --------------------------------------------------------------------------------------------------------------------- @@ -34,7 +34,7 @@ public static bool Validate(InfiniFrameNativeParameters parameters, ILogger logg } if (!string.IsNullOrWhiteSpace(windowIconFile) && - !IconFileUtilities.TryResolveIconFilePath(windowIconFile, out _)) { + !IconFileUtility.TryResolveIconFilePath(windowIconFile, out _)) { logger.LogError("WindowIconFile: {WindowIconFile} cannot be found", windowIconFile); result = false; } diff --git a/src/InfiniFrame.Shared/Utilities/ExceptionsUtility.cs b/src/InfiniFrame.Shared/Utilities/ExceptionsUtility.cs new file mode 100644 index 000000000..5177257fe --- /dev/null +++ b/src/InfiniFrame.Shared/Utilities/ExceptionsUtility.cs @@ -0,0 +1,12 @@ +// --------------------------------------------------------------------------------------------------------------------- +// Imports +// --------------------------------------------------------------------------------------------------------------------- +namespace InfiniFrame.Utilities; + +// --------------------------------------------------------------------------------------------------------------------- +// Code +// --------------------------------------------------------------------------------------------------------------------- +internal static class ExceptionsUtility { + public static bool IsNonFatalException(Exception exception) + => exception is not (OutOfMemoryException or AccessViolationException); +} diff --git a/src/InfiniFrame.Shared/Utilities/IconFileUtilities.cs b/src/InfiniFrame.Shared/Utilities/IconFileUtility.cs similarity index 97% rename from src/InfiniFrame.Shared/Utilities/IconFileUtilities.cs rename to src/InfiniFrame.Shared/Utilities/IconFileUtility.cs index f4b1427e1..4c4ca5bfe 100644 --- a/src/InfiniFrame.Shared/Utilities/IconFileUtilities.cs +++ b/src/InfiniFrame.Shared/Utilities/IconFileUtility.cs @@ -7,7 +7,7 @@ namespace InfiniFrame.Utilities; // --------------------------------------------------------------------------------------------------------------------- // Code // --------------------------------------------------------------------------------------------------------------------- -public static class IconFileUtilities { +internal static class IconFileUtility { public static bool TryResolveIconFilePath( string? filePath, [NotNullWhen(true)] out string? resolvedFilePath, diff --git a/src/InfiniFrame.Shared/Utilities/InvokeUtilities.cs b/src/InfiniFrame.Shared/Utilities/InvokeUtility.cs similarity index 98% rename from src/InfiniFrame.Shared/Utilities/InvokeUtilities.cs rename to src/InfiniFrame.Shared/Utilities/InvokeUtility.cs index 1849f44eb..7c6a3fcd1 100644 --- a/src/InfiniFrame.Shared/Utilities/InvokeUtilities.cs +++ b/src/InfiniFrame.Shared/Utilities/InvokeUtility.cs @@ -16,7 +16,7 @@ namespace InfiniFrame.Utilities; /// a synchronization primitive (e.g. ). /// /// -internal static class InvokeUtilities { +internal static class InvokeUtility { public static T? InvokeAndReturn(IInfiniFrameWindow window, Func callback) { T? value = default; // ReSharper disable once RedundantAssignment diff --git a/src/InfiniFrame.Tools.Pack/Exceptions/ExceptionsUtility.cs b/src/InfiniFrame.Tools.Pack/Exceptions/ExceptionsUtility.cs new file mode 100644 index 000000000..a1678ea52 --- /dev/null +++ b/src/InfiniFrame.Tools.Pack/Exceptions/ExceptionsUtility.cs @@ -0,0 +1,12 @@ +// --------------------------------------------------------------------------------------------------------------------- +// Imports +// --------------------------------------------------------------------------------------------------------------------- +namespace InfiniFrame.Tools.Pack.Exceptions; + +// --------------------------------------------------------------------------------------------------------------------- +// Code +// --------------------------------------------------------------------------------------------------------------------- +internal static class ExceptionsUtility { + public static bool IsNonFatalException(Exception exception) + => exception is not (OutOfMemoryException or AccessViolationException); +} diff --git a/src/InfiniFrame.Tools.Pack/Program.cs b/src/InfiniFrame.Tools.Pack/Program.cs index 80739251f..eb330fc29 100644 --- a/src/InfiniFrame.Tools.Pack/Program.cs +++ b/src/InfiniFrame.Tools.Pack/Program.cs @@ -42,7 +42,7 @@ public static async Task Main(string[] args) { Log.Error(ex, "ERROR: {Message}", ex.Message); return ExitCodes.NativeDependencyMissing; } - catch (Exception ex) when (IsNonFatalException(ex)) { + catch (Exception ex) when (ExceptionsUtility.IsNonFatalException(ex)) { Log.Error(ex, "ERROR: {Message}", ex.Message); return ExitCodes.GenericFailure; } @@ -50,7 +50,4 @@ public static async Task Main(string[] args) { await Log.CloseAndFlushAsync(); } } - - private static bool IsNonFatalException(Exception exception) - => exception is not (OutOfMemoryException or AccessViolationException); } diff --git a/src/InfiniFrame.WebServer/InfiniFrameWebApplication.cs b/src/InfiniFrame.WebServer/InfiniFrameWebApplication.cs index f078df624..88a146be8 100644 --- a/src/InfiniFrame.WebServer/InfiniFrameWebApplication.cs +++ b/src/InfiniFrame.WebServer/InfiniFrameWebApplication.cs @@ -1,6 +1,8 @@ // --------------------------------------------------------------------------------------------------------------------- // Imports // --------------------------------------------------------------------------------------------------------------------- +using InfiniFrame.Utilities; + namespace InfiniFrame.WebServer; // --------------------------------------------------------------------------------------------------------------------- // Code @@ -89,7 +91,7 @@ private async Task StopWebAppAsync(CancellationToken ct = default) { try { await WebApp.StopAsync(ct); } - catch (Exception e) when (IsNonFatalException(e)) { + catch (Exception e) when (ExceptionsUtility.IsNonFatalException(e)) { Window.Logger.LogError(e, "Error stopping web app"); } } @@ -102,7 +104,4 @@ private static async Task ObserveHostRunCompletionAsync(Task runTask) { // Host shutdown cancellation is expected. } } - - private static bool IsNonFatalException(Exception exception) - => exception is not (OutOfMemoryException or AccessViolationException); } diff --git a/src/InfiniFrame/Configuration/InfiniFrameOptionsBuilder.cs b/src/InfiniFrame/Configuration/InfiniFrameOptionsBuilder.cs index b0f3da089..d5b8ac82a 100644 --- a/src/InfiniFrame/Configuration/InfiniFrameOptionsBuilder.cs +++ b/src/InfiniFrame/Configuration/InfiniFrameOptionsBuilder.cs @@ -67,7 +67,7 @@ public string? Title { // Methods // ----------------------------------------------------------------------------------------------------------------- public InfiniFrameNativeParameters ToNativeParameters() { - IconFileUtilities.TryResolveIconFilePath(IconFilePath, out string? resolvedIconFilePath); + IconFileUtility.TryResolveIconFilePath(IconFilePath, out string? resolvedIconFilePath); if (CustomSchemeNames.Count > CustomSchemeNameMemory.MaxCustomSchemeNames) throw new InvalidOperationException("Maximum number of custom schemes is 16."); diff --git a/src/InfiniFrame/Events/InfiniFrameEvents.Messaging.cs b/src/InfiniFrame/Events/InfiniFrameEvents.Messaging.cs index 24988b83a..912c5973f 100644 --- a/src/InfiniFrame/Events/InfiniFrameEvents.Messaging.cs +++ b/src/InfiniFrame/Events/InfiniFrameEvents.Messaging.cs @@ -4,6 +4,7 @@ using InfiniFrame.Interop; using InfiniFrame.Js; using InfiniFrame.Js.Interop; +using InfiniFrame.Utilities; using Microsoft.Extensions.Logging; using System.Text.Json; @@ -75,7 +76,7 @@ public void OnWebMessageReceived(string message, string? origin = null) { ); } } - catch (Exception ex) when (IsNonFatalException(ex)) { + catch (Exception ex) when (ExceptionsUtility.IsNonFatalException(ex)) { Sender.Logger.LogError( ex, "Unhandled exception while processing postMessage '{MessageId}'", @@ -95,7 +96,7 @@ public void OnWebMessageReceived(string message, string? origin = null) { SendSuccess(Sender, parseResult.RequestId, response); } - catch (Exception ex) when (IsNonFatalException(ex)) { + catch (Exception ex) when (ExceptionsUtility.IsNonFatalException(ex)) { Sender.Logger.LogError( ex, "Unhandled exception while processing getMessage '{MessageId}'", @@ -122,9 +123,6 @@ public void OnWebMessageReceived(string message, string? origin = null) { // Helpers // --------------------------------------------------------------------------------------------------------------------- - private static bool IsNonFatalException(Exception exception) - => exception is not (OutOfMemoryException or AccessViolationException); - private static void SendSuccess(IInfiniFrameWindow window, string? requestId, string? data) { string responsePayloadJson = JsonSerializer.Serialize( new InteropGetMessageSuccessResponse { diff --git a/src/InfiniFrame.Shared/Native/InfiniFrameSingleFileBootstrap.cs b/src/InfiniFrame/InfiniFrameSingleFileBootstrap.cs similarity index 100% rename from src/InfiniFrame.Shared/Native/InfiniFrameSingleFileBootstrap.cs rename to src/InfiniFrame/InfiniFrameSingleFileBootstrap.cs diff --git a/src/InfiniFrame/Window/InfiniFrameWindow.cs b/src/InfiniFrame/Window/InfiniFrameWindow.cs index 408f0a70c..8802318b3 100644 --- a/src/InfiniFrame/Window/InfiniFrameWindow.cs +++ b/src/InfiniFrame/Window/InfiniFrameWindow.cs @@ -447,7 +447,7 @@ private static string[] GetNativeFilters((string Name, string[] Extensions)[] fi /// Thrown when accessed from a non-Windows platform. [DebuggerBrowsable(DebuggerBrowsableState.Never)] public IntPtr WindowHandle => OperatingSystem.IsWindows() - ? InvokeUtilities.InvokeAndReturn(this, InfiniFrameNative.GetWindowHandlerWin32) + ? InvokeUtility.InvokeAndReturn(this, InfiniFrameNative.GetWindowHandlerWin32) : IntPtr.Zero; /// @@ -462,7 +462,7 @@ private static string[] GetNativeFilters((string Name, string[] Extensions)[] fi /// A read-only list of Monitor objects representing information about each display monitor. /// [DebuggerBrowsable(DebuggerBrowsableState.Never)] - public ImmutableArray Monitors => InvokeUtilities.InvokeAndReturn(this, MonitorsUtility.GetMonitors); + public ImmutableArray Monitors => InvokeUtility.InvokeAndReturn(this, MonitorsUtility.GetMonitors); /// /// Retrieves the primary monitor information from the native window instance. @@ -473,7 +473,7 @@ private static string[] GetNativeFilters((string Name, string[] Extensions)[] fi /// available monitors. /// [DebuggerBrowsable(DebuggerBrowsableState.Never)] - public InfiniMonitor MainMonitor => InvokeUtilities.InvokeAndReturn(this, MonitorsUtility.GetMonitors)[0]; + public InfiniMonitor MainMonitor => InvokeUtility.InvokeAndReturn(this, MonitorsUtility.GetMonitors)[0]; /// /// Gets the dots per inch (DPI) for the primary display from the native window. @@ -482,7 +482,7 @@ private static string[] GetNativeFilters((string Name, string[] Extensions)[] fi /// An ApplicationException is thrown if the window hasn't been initialized yet. /// [DebuggerBrowsable(DebuggerBrowsableState.Never)] - public uint ScreenDpi => InvokeUtilities.InvokeAndReturn(this, InfiniFrameNative.GetScreenDpi); + public uint ScreenDpi => InvokeUtility.InvokeAndReturn(this, InfiniFrameNative.GetScreenDpi); /// /// Gets a unique GUID to identify the native window. @@ -514,48 +514,48 @@ private static string[] GetNativeFilters((string Name, string[] Extensions)[] fi [DebuggerBrowsable(DebuggerBrowsableState.Never)] public bool Transparent => OperatingSystem.IsWindows() ? Configuration.StartupParameters.Transparent// on windows it can only be set at startup - : InvokeUtilities.InvokeAndReturn(this, InfiniFrameNative.GetTransparentEnabled); + : InvokeUtility.InvokeAndReturn(this, InfiniFrameNative.GetTransparentEnabled); /// /// When true, the user can access the browser control's context menu. /// By default, this is set to true. /// [DebuggerBrowsable(DebuggerBrowsableState.Never)] - public bool ContextMenuEnabled => InvokeUtilities.InvokeAndReturn(this, InfiniFrameNative.GetContextMenuEnabled); + public bool ContextMenuEnabled => InvokeUtility.InvokeAndReturn(this, InfiniFrameNative.GetContextMenuEnabled); /// /// When true, the user can access the browser control's developer tools. /// By default, this is set to true. /// [DebuggerBrowsable(DebuggerBrowsableState.Never)] - public bool DevToolsEnabled => InvokeUtilities.InvokeAndReturn(this, InfiniFrameNative.GetDevToolsEnabled); + public bool DevToolsEnabled => InvokeUtility.InvokeAndReturn(this, InfiniFrameNative.GetDevToolsEnabled); [DebuggerBrowsable(DebuggerBrowsableState.Never)] - public bool MediaAutoplayEnabled => InvokeUtilities.InvokeAndReturn(this, InfiniFrameNative.GetMediaAutoplayEnabled); + public bool MediaAutoplayEnabled => InvokeUtility.InvokeAndReturn(this, InfiniFrameNative.GetMediaAutoplayEnabled); [DebuggerBrowsable(DebuggerBrowsableState.Never)] - public string? UserAgent => InvokeUtilities.InvokeAndReturn(this, InfiniFrameNative.GetUserAgent); + public string? UserAgent => InvokeUtility.InvokeAndReturn(this, InfiniFrameNative.GetUserAgent); [DebuggerBrowsable(DebuggerBrowsableState.Never)] - public bool FileSystemAccessEnabled => InvokeUtilities.InvokeAndReturn(this, InfiniFrameNative.GetFileSystemAccessEnabled); + public bool FileSystemAccessEnabled => InvokeUtility.InvokeAndReturn(this, InfiniFrameNative.GetFileSystemAccessEnabled); [DebuggerBrowsable(DebuggerBrowsableState.Never)] - public bool WebSecurityEnabled => InvokeUtilities.InvokeAndReturn(this, InfiniFrameNative.GetWebSecurityEnabled); + public bool WebSecurityEnabled => InvokeUtility.InvokeAndReturn(this, InfiniFrameNative.GetWebSecurityEnabled); [DebuggerBrowsable(DebuggerBrowsableState.Never)] - public bool JavascriptClipboardAccessEnabled => InvokeUtilities.InvokeAndReturn(this, InfiniFrameNative.GetJavascriptClipboardAccessEnabled); + public bool JavascriptClipboardAccessEnabled => InvokeUtility.InvokeAndReturn(this, InfiniFrameNative.GetJavascriptClipboardAccessEnabled); [DebuggerBrowsable(DebuggerBrowsableState.Never)] - public bool MediaStreamEnabled => InvokeUtilities.InvokeAndReturn(this, InfiniFrameNative.GetMediaStreamEnabled); + public bool MediaStreamEnabled => InvokeUtility.InvokeAndReturn(this, InfiniFrameNative.GetMediaStreamEnabled); [DebuggerBrowsable(DebuggerBrowsableState.Never)] - public bool SmoothScrollingEnabled => InvokeUtilities.InvokeAndReturn(this, InfiniFrameNative.GetSmoothScrollingEnabled); + public bool SmoothScrollingEnabled => InvokeUtility.InvokeAndReturn(this, InfiniFrameNative.GetSmoothScrollingEnabled); [DebuggerBrowsable(DebuggerBrowsableState.Never)] - public bool IgnoreCertificateErrorsEnabled => InvokeUtilities.InvokeAndReturn(this, InfiniFrameNative.GetIgnoreCertificateErrorsEnabled); + public bool IgnoreCertificateErrorsEnabled => InvokeUtility.InvokeAndReturn(this, InfiniFrameNative.GetIgnoreCertificateErrorsEnabled); [DebuggerBrowsable(DebuggerBrowsableState.Never)] - public bool NotificationsEnabled => InvokeUtilities.InvokeAndReturn(this, InfiniFrameNative.GetNotificationsEnabled); + public bool NotificationsEnabled => InvokeUtility.InvokeAndReturn(this, InfiniFrameNative.GetNotificationsEnabled); /// /// This property returns or sets the fullscreen status of the window. @@ -563,34 +563,34 @@ private static string[] GetNativeFilters((string Name, string[] Extensions)[] fi /// By default, this is set to false. /// [DebuggerBrowsable(DebuggerBrowsableState.Never)] - public bool FullScreen => InvokeUtilities.InvokeAndReturn(this, InfiniFrameNative.GetFullScreen); + public bool FullScreen => InvokeUtility.InvokeAndReturn(this, InfiniFrameNative.GetFullScreen); /// /// Gets whether the native browser control grants all requests for access to local resources /// such as the user's camera and microphone. By default, this is set to true. /// [DebuggerBrowsable(DebuggerBrowsableState.Never)] - public bool GrantBrowserPermissions => InvokeUtilities.InvokeAndReturn(this, InfiniFrameNative.GetGrantBrowserPermissions); + public bool GrantBrowserPermissions => InvokeUtility.InvokeAndReturn(this, InfiniFrameNative.GetGrantBrowserPermissions); /// /// Gets the Height property of the native window in pixels. /// The default value is 0. /// [DebuggerBrowsable(DebuggerBrowsableState.Never)] - public int Height => InvokeUtilities.InvokeAndReturn(this, InfiniFrameNative.GetHeight); + public int Height => InvokeUtility.InvokeAndReturn(this, InfiniFrameNative.GetHeight); /// /// Gets the icon file for the native window title bar. /// The file must be located on the local machine and cannot be a URL. The default is none. /// - public string IconFilePath => InvokeUtilities.InvokeAndReturn(this, InfiniFrameNative.GetIconFileName); + public string IconFilePath => InvokeUtility.InvokeAndReturn(this, InfiniFrameNative.GetIconFileName); /// /// Gets the native window Left (X) and Top coordinates (Y) in pixels. /// Default is 0,0 that means the window will be aligned to the top-left edge of the screen. /// [DebuggerBrowsable(DebuggerBrowsableState.Never)] - public Point Location => InvokeUtilities.InvokeAndReturn(this, InfiniFrameNative.GetPosition); + public Point Location => InvokeUtility.InvokeAndReturn(this, InfiniFrameNative.GetPosition); /// /// Gets the native window Left (X) coordinate in pixels. @@ -598,76 +598,76 @@ private static string[] GetNativeFilters((string Name, string[] Extensions)[] fi /// The default value is 0, which means the window will be aligned to the left edge of the screen. /// [DebuggerBrowsable(DebuggerBrowsableState.Never)] - public int Left => InvokeUtilities.InvokeAndReturn(this, InfiniFrameNative.GetLeft); + public int Left => InvokeUtility.InvokeAndReturn(this, InfiniFrameNative.GetLeft); /// /// Gets whether the native window is maximized. /// Default is false. /// [DebuggerBrowsable(DebuggerBrowsableState.Never)] - public bool Maximized => InvokeUtilities.InvokeAndReturn(this, InfiniFrameNative.GetMaximized); + public bool Maximized => InvokeUtility.InvokeAndReturn(this, InfiniFrameNative.GetMaximized); /// /// Gets whether the native window is currently within focus /// [DebuggerBrowsable(DebuggerBrowsableState.Never)] - public bool Focused => InvokeUtilities.InvokeAndReturn(this, InfiniFrameNative.GetFocused); + public bool Focused => InvokeUtility.InvokeAndReturn(this, InfiniFrameNative.GetFocused); /// /// Gets the maximum size of the native window in pixels. /// [DebuggerBrowsable(DebuggerBrowsableState.Never)] - public Size MaxSize => InvokeUtilities.InvokeAndReturn(this, InfiniFrameNative.GetMaxSize); + public Size MaxSize => InvokeUtility.InvokeAndReturn(this, InfiniFrameNative.GetMaxSize); /// /// Gets the native window maximum height in pixels. /// [DebuggerBrowsable(DebuggerBrowsableState.Never)] - public int MaxHeight => InvokeUtilities.InvokeAndReturn(this, InfiniFrameNative.GetMaxHeight); + public int MaxHeight => InvokeUtility.InvokeAndReturn(this, InfiniFrameNative.GetMaxHeight); /// /// Gets the native window maximum width in pixels. /// [DebuggerBrowsable(DebuggerBrowsableState.Never)] - public int MaxWidth => InvokeUtilities.InvokeAndReturn(this, InfiniFrameNative.GetMaxWidth); + public int MaxWidth => InvokeUtility.InvokeAndReturn(this, InfiniFrameNative.GetMaxWidth); /// /// Gets whether the native window is minimized (hidden). /// [DebuggerBrowsable(DebuggerBrowsableState.Never)] - public bool Minimized => InvokeUtilities.InvokeAndReturn(this, InfiniFrameNative.GetMinimized); + public bool Minimized => InvokeUtility.InvokeAndReturn(this, InfiniFrameNative.GetMinimized); /// /// Gets the minimum size of the native window in pixels. /// [DebuggerBrowsable(DebuggerBrowsableState.Never)] - public Size MinSize => InvokeUtilities.InvokeAndReturn(this, InfiniFrameNative.GetMinSize); + public Size MinSize => InvokeUtility.InvokeAndReturn(this, InfiniFrameNative.GetMinSize); /// /// Gets the native window minimum height in pixels. /// [DebuggerBrowsable(DebuggerBrowsableState.Never)] - public int MinHeight => InvokeUtilities.InvokeAndReturn(this, InfiniFrameNative.GetMinHeight); + public int MinHeight => InvokeUtility.InvokeAndReturn(this, InfiniFrameNative.GetMinHeight); /// /// Gets the native window minimum width in pixels. /// [DebuggerBrowsable(DebuggerBrowsableState.Never)] - public int MinWidth => InvokeUtilities.InvokeAndReturn(this, InfiniFrameNative.GetMinWidth); + public int MinWidth => InvokeUtility.InvokeAndReturn(this, InfiniFrameNative.GetMinWidth); /// /// Gets whether the user can resize the native window. /// Default is true. /// [DebuggerBrowsable(DebuggerBrowsableState.Never)] - public bool Resizable => InvokeUtilities.InvokeAndReturn(this, InfiniFrameNative.GetResizable); + public bool Resizable => InvokeUtility.InvokeAndReturn(this, InfiniFrameNative.GetResizable); /// /// Gets the native window Size. This represents the width and the height of the window in pixels. /// The default Size is 0,0. /// [DebuggerBrowsable(DebuggerBrowsableState.Never)] - public Size Size => InvokeUtilities.InvokeAndReturn(this, InfiniFrameNative.GetSize); + public Size Size => InvokeUtility.InvokeAndReturn(this, InfiniFrameNative.GetSize); /// /// Gets platform-specific initialization parameters for the native browser control on startup. @@ -743,28 +743,28 @@ private static string[] GetNativeFilters((string Name, string[] Extensions)[] fi /// The default is "InfiniFrame". /// [DebuggerBrowsable(DebuggerBrowsableState.Never)] - public string? Title => InvokeUtilities.InvokeAndReturn(this, InfiniFrameNative.GetTitle); + public string? Title => InvokeUtility.InvokeAndReturn(this, InfiniFrameNative.GetTitle); /// /// Gets the native window Top (Y) coordinate in pixels. /// Default is 0. /// [DebuggerBrowsable(DebuggerBrowsableState.Never)] - public int Top => InvokeUtilities.InvokeAndReturn(this, InfiniFrameNative.GetTop); + public int Top => InvokeUtility.InvokeAndReturn(this, InfiniFrameNative.GetTop); /// /// Gets whether the native window is always at the top of the z-order. /// Default is false. /// [DebuggerBrowsable(DebuggerBrowsableState.Never)] - public bool TopMost => InvokeUtilities.InvokeAndReturn(this, InfiniFrameNative.GetTopmost); + public bool TopMost => InvokeUtility.InvokeAndReturn(this, InfiniFrameNative.GetTopmost); /// /// Gets the native window width in pixels. /// Default is 0. /// [DebuggerBrowsable(DebuggerBrowsableState.Never)] - public int Width => InvokeUtilities.InvokeAndReturn(this, InfiniFrameNative.GetWidth); + public int Width => InvokeUtility.InvokeAndReturn(this, InfiniFrameNative.GetWidth); /// /// Gets the native browser control . @@ -772,10 +772,10 @@ private static string[] GetNativeFilters((string Name, string[] Extensions)[] fi /// /// 100 = 100%, 50 = 50% [DebuggerBrowsable(DebuggerBrowsableState.Never)] - public int Zoom => InvokeUtilities.InvokeAndReturn(this, InfiniFrameNative.GetZoom); + public int Zoom => InvokeUtility.InvokeAndReturn(this, InfiniFrameNative.GetZoom); [DebuggerBrowsable(DebuggerBrowsableState.Never)] - public bool ZoomEnabled => InvokeUtilities.InvokeAndReturn(this, InfiniFrameNative.GetZoomEnabled); + public bool ZoomEnabled => InvokeUtility.InvokeAndReturn(this, InfiniFrameNative.GetZoomEnabled); private static bool IsNonFatalException(Exception exception) => exception is not (OutOfMemoryException or AccessViolationException); diff --git a/tests/InfiniFrameTests.Shared/InfiniFrameServerTestUtility.cs b/tests/InfiniFrameTests.Shared/InfiniFrameServerTestUtility.cs index e51140a72..0730ba5cc 100644 --- a/tests/InfiniFrameTests.Shared/InfiniFrameServerTestUtility.cs +++ b/tests/InfiniFrameTests.Shared/InfiniFrameServerTestUtility.cs @@ -2,6 +2,7 @@ // Imports // --------------------------------------------------------------------------------------------------------------------- using InfiniFrame; +using InfiniFrame.Utilities; using InfiniFrame.WebServer; using JetBrains.Annotations; using Microsoft.AspNetCore.Builder; @@ -65,7 +66,7 @@ public static InfiniFrameServerTestUtility Create( app.WebApp.StopAsync(cancellationToken).GetAwaiter().GetResult(); } - catch (Exception ex) when (IsNonFatalException(ex)) { + catch (Exception ex) when (ExceptionsUtility.IsNonFatalException(ex)) { ready.TrySetException(ex); } }) { @@ -115,7 +116,4 @@ public void Dispose() { _thread.Interrupt(); } } - - private static bool IsNonFatalException(Exception exception) - => exception is not (OutOfMemoryException or AccessViolationException); } diff --git a/tests/InfiniFrameTests.Shared/InfiniFrameWindowTestUtility.cs b/tests/InfiniFrameTests.Shared/InfiniFrameWindowTestUtility.cs index e6a6a4c7c..94f19f549 100644 --- a/tests/InfiniFrameTests.Shared/InfiniFrameWindowTestUtility.cs +++ b/tests/InfiniFrameTests.Shared/InfiniFrameWindowTestUtility.cs @@ -2,6 +2,7 @@ // Imports // --------------------------------------------------------------------------------------------------------------------- using InfiniFrame; +using InfiniFrame.Utilities; using JetBrains.Annotations; using System.Runtime.Versioning; @@ -88,7 +89,7 @@ InfiniFrameWindowBuilder windowBuilder windowSource.SetResult(window); window.WaitForClose(); } - catch (Exception ex) when (IsNonFatalException(ex)) { + catch (Exception ex) when (ExceptionsUtility.IsNonFatalException(ex)) { windowSource.TrySetException(ex); } }) { @@ -170,7 +171,4 @@ public void Dispose() { // ignored } } - - private static bool IsNonFatalException(Exception exception) - => exception is not (OutOfMemoryException or AccessViolationException); } diff --git a/tests/InfiniFrameTests/Utilities/IconFileUtilitiesTests.cs b/tests/InfiniFrameTests/Utilities/IconFileUtilitiesTests.cs index 73e725216..d4383de09 100644 --- a/tests/InfiniFrameTests/Utilities/IconFileUtilitiesTests.cs +++ b/tests/InfiniFrameTests/Utilities/IconFileUtilitiesTests.cs @@ -8,7 +8,7 @@ namespace InfiniFrameTests.Utilities; // --------------------------------------------------------------------------------------------------------------------- // Code // --------------------------------------------------------------------------------------------------------------------- -public class IconFileUtilitiesTests { +public class IconFileUtilityTests { [Test] public async Task TryResolveIconFilePath_UsesBaseDirectoryForRelativePath() { // Arrange @@ -25,7 +25,7 @@ public async Task TryResolveIconFilePath_UsesBaseDirectoryForRelativePath() { // Act try { - found = IconFileUtilities.TryResolveIconFilePath(relativePath, out resolved, baseDirectory); + found = IconFileUtility.TryResolveIconFilePath(relativePath, out resolved, baseDirectory); } finally { Directory.Delete(baseDirectory, true); @@ -46,7 +46,7 @@ public async Task TryResolveIconFilePath_ReturnsNullForMissingPath() { bool found; string? resolved; try { - found = IconFileUtilities.TryResolveIconFilePath("missing.ico", out resolved, baseDirectory); + found = IconFileUtility.TryResolveIconFilePath("missing.ico", out resolved, baseDirectory); } finally { Directory.Delete(baseDirectory, true); diff --git a/tests/InfiniFrameTests/Utilities/InfiniFrameNativeParametersValidatorTests.cs b/tests/InfiniFrameTests/Utilities/InfiniFrameNativeParametersValidatorTests.cs index 3ae06c931..e796665a3 100644 --- a/tests/InfiniFrameTests/Utilities/InfiniFrameNativeParametersValidatorTests.cs +++ b/tests/InfiniFrameTests/Utilities/InfiniFrameNativeParametersValidatorTests.cs @@ -2,7 +2,6 @@ // Imports // --------------------------------------------------------------------------------------------------------------------- using InfiniFrame.Native; -using InfiniFrame.Utilities; using Microsoft.Extensions.Logging.Abstractions; namespace InfiniFrameTests.Utilities;