| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- namespace InABox.Avalonia.Dialogs;
- public enum MessageDialogButtonPosition
- {
- Left,
- Right
- }
- public enum MessageDialogResult
- {
- None,
- OK,
- Cancel,
- Yes,
- No,
- Other
- }
- public static class MessageDialog
- {
- public static async Task ShowMessage(string message)
- => await MessageDialogViewModel.ShowMessage(message);
- public static async Task ShowError(Exception e)
- => await MessageDialogViewModel.ShowMessage($"Error: {e.Message}");
-
- public static async Task<bool> ShowOkCancel(string message)
- => await MessageDialogViewModel.ShowOkCancel(message);
- public static async Task<bool> ShowYesNo(string message)
- => await MessageDialogViewModel.ShowYesNo(message);
- public static async Task<bool> ShowYesCancel(string message)
- => await MessageDialogViewModel.ShowYesCancel(message);
-
- public static async Task<MessageDialogResult> ShowYesNoCancel(string message)
- => await MessageDialogViewModel.ShowYesNoCancel(message);
- /// <summary>
- /// When <paramref name="task"/> has finished, show a message dialog with the error if the task failed.
- /// </summary>
- /// <remarks>
- /// Call this on the main thread. Use if spinning of a task that you don't care about the result, but don't want to fail silently.
- /// </remarks>
- /// <param name="task"></param>
- /// <returns></returns>
- public static Task ErrorIfFail(this Task task, bool shouldLog = true)
- {
- return task.ContinueWith(async t =>
- {
- if(t.Exception is AggregateException e && e.InnerException is not null)
- {
- MobileLogging.Log(e);
- await ShowError(e.InnerException);
- }
- else if(t.Exception is not null)
- {
- MobileLogging.Log(t.Exception);
- await ShowError(t.Exception);
- }
- }, TaskScheduler.FromCurrentSynchronizationContext());
- }
- }
|