Move shared GUI code into AppScaffolding
This commit is contained in:
parent
b351033cec
commit
e3c9f70dff
@ -1,6 +1,4 @@
|
||||
using System;
|
||||
|
||||
namespace LibationWinForms.ProcessQueue
|
||||
namespace AppScaffolding
|
||||
{
|
||||
public interface ILogForm
|
||||
{
|
||||
@ -1,10 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace LibationWinForms.ProcessQueue
|
||||
namespace AppScaffolding
|
||||
{
|
||||
// decouple serilog and form. include convenience factory method
|
||||
public class LogMe
|
||||
@ -1,9 +1,9 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
|
||||
namespace LibationAvalonia
|
||||
namespace AppScaffolding
|
||||
{
|
||||
internal class ObjectComparer<T> : IComparer where T : IComparable
|
||||
public class ObjectComparer<T> : IComparer where T : IComparable
|
||||
{
|
||||
public int Compare(object x, object y) => ((T)x).CompareTo(y);
|
||||
}
|
||||
@ -1,58 +0,0 @@
|
||||
using Avalonia.Threading;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace LibationAvalonia
|
||||
{
|
||||
public interface ILogForm
|
||||
{
|
||||
void WriteLine(string text);
|
||||
}
|
||||
|
||||
// decouple serilog and form. include convenience factory method
|
||||
public class LogMe
|
||||
{
|
||||
public event EventHandler<string> LogInfo;
|
||||
public event EventHandler<string> LogErrorString;
|
||||
public event EventHandler<(Exception, string)> LogError;
|
||||
|
||||
private LogMe()
|
||||
{
|
||||
LogInfo += (_, text) => Serilog.Log.Logger.Information($"Automated backup: {text}");
|
||||
LogErrorString += (_, text) => Serilog.Log.Logger.Error(text);
|
||||
LogError += (_, tuple) => Serilog.Log.Logger.Error(tuple.Item1, tuple.Item2 ?? "Automated backup: error");
|
||||
}
|
||||
private static ILogForm LogForm;
|
||||
public static LogMe RegisterForm<T>(T form) where T : ILogForm
|
||||
{
|
||||
var logMe = new LogMe();
|
||||
|
||||
if (form is null)
|
||||
return logMe;
|
||||
|
||||
LogForm = form;
|
||||
|
||||
logMe.LogInfo += LogMe_LogInfo;
|
||||
logMe.LogErrorString += LogMe_LogErrorString;
|
||||
logMe.LogError += LogMe_LogError;
|
||||
|
||||
return logMe;
|
||||
}
|
||||
|
||||
private static async void LogMe_LogError(object sender, (Exception, string) tuple)
|
||||
{
|
||||
await Dispatcher.UIThread.InvokeAsync(() => LogForm?.WriteLine(tuple.Item2 ?? "Automated backup: error"));
|
||||
await Dispatcher.UIThread.InvokeAsync(() => LogForm?.WriteLine("ERROR: " + tuple.Item1.Message));
|
||||
}
|
||||
|
||||
private static async void LogMe_LogErrorString(object sender, string text)
|
||||
=> await Dispatcher.UIThread.InvokeAsync(() => LogForm?.WriteLine(text));
|
||||
|
||||
private static async void LogMe_LogInfo(object sender, string text)
|
||||
=> await Dispatcher.UIThread.InvokeAsync(() => LogForm?.WriteLine(text));
|
||||
|
||||
public void Info(string text) => LogInfo?.Invoke(this, text);
|
||||
public void Error(string text) => LogErrorString?.Invoke(this, text);
|
||||
public void Error(Exception ex, string text = null) => LogError?.Invoke(this, (ex, text));
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,5 @@
|
||||
using ApplicationServices;
|
||||
using AppScaffolding;
|
||||
using Avalonia.Media;
|
||||
using DataLayer;
|
||||
using Dinah.Core;
|
||||
|
||||
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using ApplicationServices;
|
||||
using AppScaffolding;
|
||||
using AudibleApi;
|
||||
using AudibleApi.Common;
|
||||
using Avalonia.Media;
|
||||
@ -394,7 +395,7 @@ $@" Title: {libraryBook.Book.Title}
|
||||
return ProcessBookResult.FailedRetry;
|
||||
}
|
||||
|
||||
private string SkipDialogText => @"
|
||||
private static string SkipDialogText => @"
|
||||
An error occurred while trying to process this book.
|
||||
{0}
|
||||
|
||||
@ -404,9 +405,9 @@ An error occurred while trying to process this book.
|
||||
|
||||
- IGNORE: Permanently ignore this book. Continue processing books. (Will not try this book again later.)
|
||||
".Trim();
|
||||
private MessageBoxButtons SkipDialogButtons => MessageBoxButtons.AbortRetryIgnore;
|
||||
private MessageBoxDefaultButton SkipDialogDefaultButton => MessageBoxDefaultButton.Button1;
|
||||
private DialogResult SkipResult => DialogResult.Ignore;
|
||||
private static MessageBoxButtons SkipDialogButtons => MessageBoxButtons.AbortRetryIgnore;
|
||||
private static MessageBoxDefaultButton SkipDialogDefaultButton => MessageBoxDefaultButton.Button1;
|
||||
private static DialogResult SkipResult => DialogResult.Ignore;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using ApplicationServices;
|
||||
using AppScaffolding;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Threading;
|
||||
using DataLayer;
|
||||
|
||||
@ -5,6 +5,7 @@ using Avalonia.Markup.Xaml;
|
||||
using LibationAvalonia.ViewModels;
|
||||
using ApplicationServices;
|
||||
using DataLayer;
|
||||
using AppScaffolding;
|
||||
|
||||
namespace LibationAvalonia.Views
|
||||
{
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using ApplicationServices;
|
||||
using AppScaffolding;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Data.Converters;
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using ApplicationServices;
|
||||
using AppScaffolding;
|
||||
using DataLayer;
|
||||
using Dinah.Core;
|
||||
using Dinah.Core.DataBinding;
|
||||
|
||||
@ -1,10 +0,0 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
|
||||
namespace LibationWinForms
|
||||
{
|
||||
internal class ObjectComparer<T> : IComparer where T : IComparable
|
||||
{
|
||||
public int Compare(object x, object y) => ((T)x).CompareTo(y);
|
||||
}
|
||||
}
|
||||
@ -15,6 +15,7 @@ using Dinah.Core.ErrorHandling;
|
||||
using Dinah.Core.WindowsDesktop.Drawing;
|
||||
using FileLiberator;
|
||||
using LibationFileManager;
|
||||
using AppScaffolding;
|
||||
|
||||
namespace LibationWinForms.ProcessQueue
|
||||
{
|
||||
|
||||
@ -6,6 +6,7 @@ using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using ApplicationServices;
|
||||
using AppScaffolding;
|
||||
using LibationFileManager;
|
||||
|
||||
namespace LibationWinForms.ProcessQueue
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user