From 1eafafcbec644c3d2301d6a1742d22619c663050 Mon Sep 17 00:00:00 2001 From: Justin Swanson Date: Mon, 21 Oct 2019 22:03:01 -0500 Subject: [PATCH] WorkQueue concepts migrated to MainWindowVM Since WorkQueue is static itself, just put it in the main vm. If it ever gets made into a non-singleton, might refactor installer and compiler VMs to each have work queue systems --- Wabbajack/Util/CPUStatus.cs | 15 ++++++++++ Wabbajack/View Models/AppState.cs | 41 ++------------------------- Wabbajack/View Models/MainWindowVM.cs | 41 +++++++++++++++++++++++++-- Wabbajack/Views/MainWindow.xaml | 4 +-- Wabbajack/Wabbajack.csproj | 1 + 5 files changed, 60 insertions(+), 42 deletions(-) create mode 100644 Wabbajack/Util/CPUStatus.cs diff --git a/Wabbajack/Util/CPUStatus.cs b/Wabbajack/Util/CPUStatus.cs new file mode 100644 index 00000000..0a218d7a --- /dev/null +++ b/Wabbajack/Util/CPUStatus.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Wabbajack +{ + public class CPUStatus + { + public int Progress { get; internal set; } + public string Msg { get; internal set; } + public int ID { get; internal set; } + } +} diff --git a/Wabbajack/View Models/AppState.cs b/Wabbajack/View Models/AppState.cs index ae5c6bf2..f283655b 100644 --- a/Wabbajack/View Models/AppState.cs +++ b/Wabbajack/View Models/AppState.cs @@ -32,14 +32,12 @@ namespace Wabbajack public class AppState : ViewModel, IDataErrorInfo { public SlideShow Slideshow { get; } + public MainWindowVM MWVM { get; } private string _mo2Folder; public readonly BitmapImage _noneImage = UIUtils.BitmapImageFromResource("Wabbajack.Resources.none.jpg"); - private readonly Subject _statusSubject = new Subject(); - public ObservableCollectionExtended Status { get; } = new ObservableCollectionExtended(); - private ModList _ModList; public ModList ModList { get => _ModList; private set => this.RaiseAndSetIfChanged(ref _ModList, value); } @@ -69,7 +67,7 @@ namespace Wabbajack public IReactiveCommand OpenReadmeCommand { get; } public IReactiveCommand OpenModListPropertiesCommand { get; } - public AppState(RunMode mode) + public AppState(MainWindowVM mainWindowVM, RunMode mode) { if (Path.GetDirectoryName(Assembly.GetEntryAssembly().Location.ToLower()) == KnownFolders.Downloads.Path.ToLower()) { @@ -82,6 +80,7 @@ namespace Wabbajack Environment.Exit(1); } + this.MWVM = mainWindowVM; Mode = mode; // Define commands @@ -103,22 +102,6 @@ namespace Wabbajack .ObserveOnGuiThread()); this.Slideshow = new SlideShow(this); - - // Initialize work queue - WorkQueue.Init( - report_function: (id, msg, progress) => this._statusSubject.OnNext(new CPUStatus() { ID = id, Msg = msg, Progress = progress }), - report_queue_size: (max, current) => this.SetQueueSize(max, current)); - // Compile progress updates and populate ObservableCollection - this._statusSubject - .ObserveOn(RxApp.TaskpoolScheduler) - .ToObservableChangeSet(x => x.ID) - .Batch(TimeSpan.FromMilliseconds(250)) - .EnsureUniqueChanges() - .ObserveOn(RxApp.MainThreadScheduler) - .Sort(SortExpressionComparer.Ascending(s => s.ID), SortOptimisations.ComparesImmutableValuesOnly) - .Bind(this.Status) - .Subscribe() - .DisposeWith(this.CompositeDisposable); } public ObservableCollection Log { get; } = new ObservableCollection(); @@ -132,9 +115,6 @@ namespace Wabbajack private string _DownloadLocation; public string DownloadLocation { get => _DownloadLocation; set => this.RaiseAndSetIfChanged(ref _DownloadLocation, value); } - private int _queueProgress; - public int QueueProgress { get => _queueProgress; set => this.RaiseAndSetIfChanged(ref _queueProgress, value); } - public string LogFile { get; } private void ExecuteChangePath() @@ -258,14 +238,6 @@ namespace Wabbajack Application.Current.Dispatcher.Invoke(() => Log.Add(msg)); } - public void SetQueueSize(int max, int current) - { - if (max == 0) - max = 1; - var total = current * 100 / max; - QueueProgress = total; - } - private void ConfigureForBuild() { var profile_folder = Path.GetDirectoryName(Location); @@ -384,11 +356,4 @@ namespace Wabbajack } } } - - public class CPUStatus - { - public int Progress { get; internal set; } - public string Msg { get; internal set; } - public int ID { get; internal set; } - } } \ No newline at end of file diff --git a/Wabbajack/View Models/MainWindowVM.cs b/Wabbajack/View Models/MainWindowVM.cs index 52d5124b..204926e5 100644 --- a/Wabbajack/View Models/MainWindowVM.cs +++ b/Wabbajack/View Models/MainWindowVM.cs @@ -1,9 +1,15 @@ -using ReactiveUI; +using DynamicData; +using DynamicData.Binding; +using ReactiveUI; using System; using System.Collections.Generic; using System.Linq; +using System.Reactive.Disposables; +using System.Reactive.Linq; +using System.Reactive.Subjects; using System.Text; using System.Threading.Tasks; +using Wabbajack.Common; using Wabbajack.Lib; namespace Wabbajack @@ -15,9 +21,40 @@ namespace Wabbajack private ViewModel _ActivePane; public ViewModel ActivePane { get => _ActivePane; set => this.RaiseAndSetIfChanged(ref _ActivePane, value); } + private int _QueueProgress; + public int QueueProgress { get => _QueueProgress; set => this.RaiseAndSetIfChanged(ref _QueueProgress, value); } + + private readonly Subject _statusSubject = new Subject(); + public IObservable StatusObservable => _statusSubject; + public ObservableCollectionExtended StatusList { get; } = new ObservableCollectionExtended(); + public MainWindowVM(RunMode mode) { - this.AppState = new AppState(mode); + this.AppState = new AppState(this, mode); + + // Initialize work queue + WorkQueue.Init( + report_function: (id, msg, progress) => this._statusSubject.OnNext(new CPUStatus() { ID = id, Msg = msg, Progress = progress }), + report_queue_size: (max, current) => this.SetQueueSize(max, current)); + + // Compile progress updates and populate ObservableCollection + this._statusSubject + .ObserveOn(RxApp.TaskpoolScheduler) + .ToObservableChangeSet(x => x.ID) + .Batch(TimeSpan.FromMilliseconds(250)) + .EnsureUniqueChanges() + .ObserveOn(RxApp.MainThreadScheduler) + .Sort(SortExpressionComparer.Ascending(s => s.ID), SortOptimisations.ComparesImmutableValuesOnly) + .Bind(this.StatusList) + .Subscribe() + .DisposeWith(this.CompositeDisposable); + } + + private void SetQueueSize(int max, int current) + { + if (max == 0) + max = 1; + QueueProgress = current * 100 / max; } } } diff --git a/Wabbajack/Views/MainWindow.xaml b/Wabbajack/Views/MainWindow.xaml index e93334b2..47c3e5c1 100644 --- a/Wabbajack/Views/MainWindow.xaml +++ b/Wabbajack/Views/MainWindow.xaml @@ -61,7 +61,7 @@ Background="#444444" Maximum="100" Minimum="0" - Value="{Binding QueueProgress}" /> + Value="{Binding MWVM.QueueProgress}" /> + ItemsSource="{Binding MWVM.StatusList}"> diff --git a/Wabbajack/Wabbajack.csproj b/Wabbajack/Wabbajack.csproj index 715df394..88861a91 100644 --- a/Wabbajack/Wabbajack.csproj +++ b/Wabbajack/Wabbajack.csproj @@ -227,6 +227,7 @@ + SlideshowView.xaml