Przeglądaj źródła

avalonia: added exception handling to AvaloniaMenuItems
also added Client.QueryAsync

Kenric Nugteren 1 miesiąc temu
rodzic
commit
47ebb7f14b

+ 8 - 1
InABox.Avalonia/Components/MenuPanel/AvaloniaMenuItem.cs

@@ -57,7 +57,14 @@ public partial class AvaloniaMenuItem : ObservableObject
             }
             else if (action != null)
             {
-                _ = action();
+                var task = action();
+                task.ContinueWith(task =>
+                {
+                    if (task.Exception is not null)
+                    {
+                        MobileLogging.Log(task.Exception);
+                    }
+                });
             }
         });
 

+ 15 - 0
InABox.Avalonia/Logging/MobileLogging.cs

@@ -19,6 +19,10 @@ namespace InABox.Avalonia
         private static Logger _logger = null;
 
         private static string _logfilenameincludingpath;
+
+        public delegate void ExceptionHandler(Exception ex, string? tag);
+
+        public static event ExceptionHandler? LogException;
         
         private static Logger CheckLogger()
         {
@@ -57,8 +61,19 @@ namespace InABox.Avalonia
             CheckLogger()
                 .Information("{Log}", message);
         }
+        
+        public static void LogError(string message)
+        {
+            CheckLogger()
+                .Error("{Log}", message);
+        }
 
         public static void Log(Exception exception, String tag = "")
+        {
+            LogException?.Invoke(exception, tag);
+        }
+
+        public static void LogExceptionMessage(Exception exception, string tag = "")
         {
             CheckLogger();
             if (String.IsNullOrWhiteSpace(tag))

+ 6 - 0
InABox.Core/Client/Client.cs

@@ -236,6 +236,12 @@ namespace InABox.Clients
             return new Client<TEntity>().Query(filter, columns, orderby, range);
         }
 
+        public static Task<CoreTable> QueryAsync<TEntity>(Filter<TEntity>? filter = null, Columns<TEntity>? columns = null, SortOrder<TEntity>? orderby = null, CoreRange? range = null)
+            where TEntity : Entity, IRemotable, new()
+        {
+            return Task.Run(() => new Client<TEntity>().Query(filter, columns, orderby, range));
+        }
+
         public static void Query<TEntity>(Filter<TEntity>? filter, Columns<TEntity>? columns, SortOrder<TEntity>? orderby, CoreRange? range, Action<CoreTable?, Exception?> callback)
             where TEntity : Entity, IRemotable, new()
         {