Remove references to winforms
This commit is contained in:
parent
ab731a63af
commit
6aa0a1f8b9
61
Source/LibationWinForms/AvaloniaUI/LogMe.cs
Normal file
61
Source/LibationWinForms/AvaloniaUI/LogMe.cs
Normal file
@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace LibationWinForms.AvaloniaUI
|
||||
{
|
||||
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 Task.Run(() => LogForm?.WriteLine(tuple.Item2 ?? "Automated backup: error"));
|
||||
await Task.Run(() => LogForm?.WriteLine("ERROR: " + tuple.Item1.Message));
|
||||
}
|
||||
|
||||
private static async void LogMe_LogErrorString(object sender, string text)
|
||||
{
|
||||
await Task.Run(() => LogForm?.WriteLine(text));
|
||||
}
|
||||
|
||||
private static async void LogMe_LogInfo(object sender, string text)
|
||||
{
|
||||
await Task.Run(() => 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));
|
||||
}
|
||||
}
|
||||
@ -4,7 +4,6 @@ using Dinah.Core;
|
||||
using Dinah.Core.DataBinding;
|
||||
using Dinah.Core.Drawing;
|
||||
using LibationFileManager;
|
||||
using LibationWinForms.GridView;
|
||||
using ReactiveUI;
|
||||
using System;
|
||||
using System.Collections;
|
||||
|
||||
@ -89,9 +89,9 @@ namespace LibationWinForms.AvaloniaUI.ViewModels
|
||||
private Processable NextProcessable() => _currentProcessable = null;
|
||||
private Processable _currentProcessable;
|
||||
private readonly Queue<Func<Processable>> Processes = new();
|
||||
private readonly ProcessQueue.LogMe Logger;
|
||||
private readonly LogMe Logger;
|
||||
|
||||
public ProcessBookViewModel(LibraryBook libraryBook, ProcessQueue.LogMe logme)
|
||||
public ProcessBookViewModel(LibraryBook libraryBook, LogMe logme)
|
||||
{
|
||||
LibraryBook = libraryBook;
|
||||
Logger = logme;
|
||||
|
||||
@ -11,7 +11,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace LibationWinForms.AvaloniaUI.ViewModels
|
||||
{
|
||||
public class ProcessQueueViewModel : ViewModelBase, ProcessQueue.ILogForm
|
||||
public class ProcessQueueViewModel : ViewModelBase, ILogForm
|
||||
{
|
||||
public ObservableCollection<LogEntry> LogEntries { get; } = new();
|
||||
public TrackedQueue<ProcessBookViewModel> Items { get; } = new();
|
||||
@ -21,13 +21,13 @@ namespace LibationWinForms.AvaloniaUI.ViewModels
|
||||
public Task QueueRunner { get; private set; }
|
||||
public bool Running => !QueueRunner?.IsCompleted ?? false;
|
||||
|
||||
private readonly ProcessQueue.LogMe Logger;
|
||||
private readonly LogMe Logger;
|
||||
|
||||
public ProcessQueueViewModel()
|
||||
{
|
||||
Queue.QueuededCountChanged += Queue_QueuededCountChanged;
|
||||
Queue.CompletedCountChanged += Queue_CompletedCountChanged;
|
||||
Logger = ProcessQueue.LogMe.RegisterForm(this);
|
||||
Logger = LogMe.RegisterForm(this);
|
||||
}
|
||||
|
||||
private int _completedCount;
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
using Avalonia.Input;
|
||||
using LibationWinForms.Dialogs;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
using Avalonia.Controls;
|
||||
using LibationFileManager;
|
||||
using LibationWinForms.Dialogs;
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
using AudibleUtilities;
|
||||
using LibationWinForms.Dialogs;
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
|
||||
@ -2,7 +2,6 @@
|
||||
using AudibleUtilities;
|
||||
using Avalonia.Controls;
|
||||
using LibationFileManager;
|
||||
using LibationWinForms.Dialogs;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
using LibationWinForms.Dialogs;
|
||||
using System;
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace LibationWinForms.AvaloniaUI.Views
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
using ApplicationServices;
|
||||
using Avalonia.Threading;
|
||||
using DataLayer;
|
||||
using LibationWinForms.Dialogs;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@ -23,7 +23,7 @@ namespace LibationWinForms.AvaloniaUI.Views
|
||||
using var context = DbContexts.GetContext();
|
||||
DataContext = new ProcessBookViewModel(
|
||||
context.GetLibraryBook_Flat_NoTracking("B017V4IM1G"),
|
||||
ProcessQueue.LogMe.RegisterForm(default(ProcessQueue.ILogForm))
|
||||
LogMe.RegisterForm(default(ILogForm))
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -26,7 +26,7 @@ namespace LibationWinForms.AvaloniaUI.Views
|
||||
if (Design.IsDesignMode)
|
||||
{
|
||||
var vm = new ProcessQueueViewModel();
|
||||
var Logger = ProcessQueue.LogMe.RegisterForm(vm);
|
||||
var Logger = LogMe.RegisterForm(vm);
|
||||
DataContext = vm;
|
||||
using var context = DbContexts.GetContext();
|
||||
List<ProcessBookViewModel> testList = new()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user