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.DataBinding;
|
||||||
using Dinah.Core.Drawing;
|
using Dinah.Core.Drawing;
|
||||||
using LibationFileManager;
|
using LibationFileManager;
|
||||||
using LibationWinForms.GridView;
|
|
||||||
using ReactiveUI;
|
using ReactiveUI;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
|
|||||||
@ -89,9 +89,9 @@ namespace LibationWinForms.AvaloniaUI.ViewModels
|
|||||||
private Processable NextProcessable() => _currentProcessable = null;
|
private Processable NextProcessable() => _currentProcessable = null;
|
||||||
private Processable _currentProcessable;
|
private Processable _currentProcessable;
|
||||||
private readonly Queue<Func<Processable>> Processes = new();
|
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;
|
LibraryBook = libraryBook;
|
||||||
Logger = logme;
|
Logger = logme;
|
||||||
|
|||||||
@ -11,7 +11,7 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace LibationWinForms.AvaloniaUI.ViewModels
|
namespace LibationWinForms.AvaloniaUI.ViewModels
|
||||||
{
|
{
|
||||||
public class ProcessQueueViewModel : ViewModelBase, ProcessQueue.ILogForm
|
public class ProcessQueueViewModel : ViewModelBase, ILogForm
|
||||||
{
|
{
|
||||||
public ObservableCollection<LogEntry> LogEntries { get; } = new();
|
public ObservableCollection<LogEntry> LogEntries { get; } = new();
|
||||||
public TrackedQueue<ProcessBookViewModel> Items { get; } = new();
|
public TrackedQueue<ProcessBookViewModel> Items { get; } = new();
|
||||||
@ -21,13 +21,13 @@ namespace LibationWinForms.AvaloniaUI.ViewModels
|
|||||||
public Task QueueRunner { get; private set; }
|
public Task QueueRunner { get; private set; }
|
||||||
public bool Running => !QueueRunner?.IsCompleted ?? false;
|
public bool Running => !QueueRunner?.IsCompleted ?? false;
|
||||||
|
|
||||||
private readonly ProcessQueue.LogMe Logger;
|
private readonly LogMe Logger;
|
||||||
|
|
||||||
public ProcessQueueViewModel()
|
public ProcessQueueViewModel()
|
||||||
{
|
{
|
||||||
Queue.QueuededCountChanged += Queue_QueuededCountChanged;
|
Queue.QueuededCountChanged += Queue_QueuededCountChanged;
|
||||||
Queue.CompletedCountChanged += Queue_CompletedCountChanged;
|
Queue.CompletedCountChanged += Queue_CompletedCountChanged;
|
||||||
Logger = ProcessQueue.LogMe.RegisterForm(this);
|
Logger = LogMe.RegisterForm(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int _completedCount;
|
private int _completedCount;
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
using Avalonia.Input;
|
using Avalonia.Input;
|
||||||
using LibationWinForms.Dialogs;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
using LibationFileManager;
|
using LibationFileManager;
|
||||||
using LibationWinForms.Dialogs;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
using AudibleUtilities;
|
using AudibleUtilities;
|
||||||
using LibationWinForms.Dialogs;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
|
|||||||
@ -2,7 +2,6 @@
|
|||||||
using AudibleUtilities;
|
using AudibleUtilities;
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
using LibationFileManager;
|
using LibationFileManager;
|
||||||
using LibationWinForms.Dialogs;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
using LibationWinForms.Dialogs;
|
using System;
|
||||||
using System;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
namespace LibationWinForms.AvaloniaUI.Views
|
namespace LibationWinForms.AvaloniaUI.Views
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
using ApplicationServices;
|
using ApplicationServices;
|
||||||
using Avalonia.Threading;
|
using Avalonia.Threading;
|
||||||
using DataLayer;
|
using DataLayer;
|
||||||
using LibationWinForms.Dialogs;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|||||||
@ -23,7 +23,7 @@ namespace LibationWinForms.AvaloniaUI.Views
|
|||||||
using var context = DbContexts.GetContext();
|
using var context = DbContexts.GetContext();
|
||||||
DataContext = new ProcessBookViewModel(
|
DataContext = new ProcessBookViewModel(
|
||||||
context.GetLibraryBook_Flat_NoTracking("B017V4IM1G"),
|
context.GetLibraryBook_Flat_NoTracking("B017V4IM1G"),
|
||||||
ProcessQueue.LogMe.RegisterForm(default(ProcessQueue.ILogForm))
|
LogMe.RegisterForm(default(ILogForm))
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -26,7 +26,7 @@ namespace LibationWinForms.AvaloniaUI.Views
|
|||||||
if (Design.IsDesignMode)
|
if (Design.IsDesignMode)
|
||||||
{
|
{
|
||||||
var vm = new ProcessQueueViewModel();
|
var vm = new ProcessQueueViewModel();
|
||||||
var Logger = ProcessQueue.LogMe.RegisterForm(vm);
|
var Logger = LogMe.RegisterForm(vm);
|
||||||
DataContext = vm;
|
DataContext = vm;
|
||||||
using var context = DbContexts.GetContext();
|
using var context = DbContexts.GetContext();
|
||||||
List<ProcessBookViewModel> testList = new()
|
List<ProcessBookViewModel> testList = new()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user