2021-12-26 21:56:44 +00:00
|
|
|
|
using ReactiveUI;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Reactive.Linq;
|
|
|
|
|
using System.Windows.Media.Imaging;
|
2021-12-27 05:18:52 +00:00
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using Wabbajack.DTOs.DownloadStates;
|
2021-12-30 00:15:37 +00:00
|
|
|
|
using Wabbajack;
|
2021-12-26 21:56:44 +00:00
|
|
|
|
|
|
|
|
|
namespace Wabbajack
|
|
|
|
|
{
|
|
|
|
|
public class ModVM : ViewModel
|
|
|
|
|
{
|
2021-12-27 05:18:52 +00:00
|
|
|
|
private readonly ILogger<ModVM> _logger;
|
2021-12-26 21:56:44 +00:00
|
|
|
|
public IMetaState State { get; }
|
|
|
|
|
|
|
|
|
|
// Image isn't exposed as a direct property, but as an observable.
|
|
|
|
|
// This acts as a caching mechanism, as interested parties will trigger it to be created,
|
|
|
|
|
// and the cached image will automatically be released when the last interested party is gone.
|
|
|
|
|
public IObservable<BitmapImage> ImageObservable { get; }
|
|
|
|
|
|
2021-12-27 05:18:52 +00:00
|
|
|
|
public ModVM(ILogger<ModVM> logger, IMetaState state)
|
2021-12-26 21:56:44 +00:00
|
|
|
|
{
|
2021-12-27 05:18:52 +00:00
|
|
|
|
_logger = logger;
|
2021-12-26 21:56:44 +00:00
|
|
|
|
State = state;
|
|
|
|
|
|
2021-12-27 05:18:52 +00:00
|
|
|
|
ImageObservable = Observable.Return(State.ImageURL?.ToString())
|
2021-12-26 21:56:44 +00:00
|
|
|
|
.ObserveOn(RxApp.TaskpoolScheduler)
|
2021-12-30 00:15:37 +00:00
|
|
|
|
.DownloadBitmapImage(ex => _logger.LogError(ex, "Skipping slide for mod {Name}", State.Name), LoadingLock)
|
2021-12-26 21:56:44 +00:00
|
|
|
|
.Replay(1)
|
|
|
|
|
.RefCount(TimeSpan.FromMilliseconds(5000));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|