Container traits to extensions
This commit is contained in:
@@ -1,9 +0,0 @@
|
||||
using FileTime.Core.ContentAccess;
|
||||
using FileTime.Core.Models;
|
||||
|
||||
namespace FileTime.App.ContainerSizeScanner;
|
||||
|
||||
public interface IContainerScanSnapshotProvider : IContentProvider
|
||||
{
|
||||
ISizeScanTask StartSizeScan(IContainer scanSizeOf);
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
using FileTime.App.Core.Services;
|
||||
using FileTime.Core.ContentAccess;
|
||||
using FileTime.Core.Models;
|
||||
|
||||
namespace FileTime.App.ContainerSizeScanner;
|
||||
|
||||
public interface IContainerSizeScanProvider : IContentProvider, IExitHandler
|
||||
{
|
||||
ISizeScanTask StartSizeScan(IContainer scanSizeOf);
|
||||
}
|
||||
@@ -1,17 +1,16 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using DeclarativeProperty;
|
||||
using FileTime.Core.Models;
|
||||
using FileTime.Core.Models.ContainerTraits;
|
||||
|
||||
namespace FileTime.App.ContainerSizeScanner;
|
||||
|
||||
public interface ISizeScanContainer : ISizeItem, IContainer, IStatusProviderContainer
|
||||
public interface ISizeScanContainer : ISizeItem, IContainer
|
||||
{
|
||||
public Task AddSizeSourceAsync(IDeclarativeProperty<long> sizeElement);
|
||||
ObservableCollection<ISizeScanContainer> ChildContainers { get; }
|
||||
ObservableCollection<ISizeScanElement> ChildElements { get; }
|
||||
ObservableCollection<ISizeItem> SizeItems { get; }
|
||||
IContainer RealContainer { get; init; }
|
||||
Task StartLoadingAsync();
|
||||
Task StopLoadingAsync();
|
||||
Task AddSizeChildAsync(ISizeItem newChild);
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using FileTime.App.Core.Exceptions;
|
||||
using FileTime.App.Core.Services;
|
||||
using FileTime.Core.ContentAccess;
|
||||
using FileTime.Core.Enums;
|
||||
using FileTime.Core.Models;
|
||||
@@ -7,14 +8,14 @@ using InitableService;
|
||||
|
||||
namespace FileTime.App.ContainerSizeScanner;
|
||||
|
||||
public class ContainerScanProvider : ContentProviderBase, IContainerScanSnapshotProvider
|
||||
public class ContainerSizeSizeScanProvider : ContentProviderBase, IContainerSizeScanProvider
|
||||
{
|
||||
private readonly ITimelessContentProvider _timelessContentProvider;
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
private readonly List<ISizeScanTask> _sizeScanTasks = new();
|
||||
internal const string ContentProviderName = "container-size-scan";
|
||||
|
||||
public ContainerScanProvider(
|
||||
public ContainerSizeSizeScanProvider(
|
||||
ITimelessContentProvider timelessContentProvider,
|
||||
IServiceProvider serviceProvider)
|
||||
: base(ContentProviderName, timelessContentProvider)
|
||||
@@ -110,4 +111,20 @@ public class ContainerScanProvider : ContentProviderBase, IContainerScanSnapshot
|
||||
|
||||
return searchTask;
|
||||
}
|
||||
|
||||
public Task ExitAsync(CancellationToken token = default)
|
||||
{
|
||||
foreach (var sizeScanTask in _sizeScanTasks)
|
||||
{
|
||||
try
|
||||
{
|
||||
sizeScanTask.Stop();
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
@@ -5,14 +5,15 @@ using DeclarativeProperty;
|
||||
using FileTime.Core.ContentAccess;
|
||||
using FileTime.Core.Enums;
|
||||
using FileTime.Core.Models;
|
||||
using FileTime.Core.Models.ContainerTraits;
|
||||
using FileTime.Core.Models.Extensions;
|
||||
using FileTime.Core.Timeline;
|
||||
|
||||
namespace FileTime.App.ContainerSizeScanner;
|
||||
|
||||
//TODO: create readonly version
|
||||
public record SizeScanContainer : ISizeScanContainer, IEscHandlerContainer
|
||||
//TODO: create readonly version, or not...
|
||||
public record SizeScanContainer : ISizeScanContainer
|
||||
{
|
||||
private readonly ITimelessContentProvider _timelessContentProvider;
|
||||
private readonly ReadOnlyExtensionCollection _readOnlyExtensions;
|
||||
private readonly BehaviorSubject<bool> _isLoading = new(false);
|
||||
private readonly CombineProperty<long, long> _size;
|
||||
@@ -38,25 +39,35 @@ public record SizeScanContainer : ISizeScanContainer, IEscHandlerContainer
|
||||
public ObservableCollection<AbsolutePath> Items { get; } = new();
|
||||
public IObservable<bool> IsLoading { get; }
|
||||
public bool? IsLoaded { get; private set; }
|
||||
public Task WaitForLoaded(CancellationToken token = default) => throw new NotImplementedException();
|
||||
|
||||
public async Task WaitForLoaded(CancellationToken token = default)
|
||||
{
|
||||
while (IsLoaded != true) await Task.Delay(1, token);
|
||||
}
|
||||
|
||||
public bool AllowRecursiveDeletion => false;
|
||||
|
||||
public IDeclarativeProperty<long> Size { get; }
|
||||
|
||||
public ObservableCollection<ISizeScanContainer> ChildContainers { get; } = new();
|
||||
public ObservableCollection<ISizeScanElement> ChildElements { get; } = new();
|
||||
public ObservableCollection<ISizeItem> SizeItems { get; } = new();
|
||||
public required IContainer RealContainer { get; init; }
|
||||
|
||||
internal SizeScanContainer()
|
||||
internal SizeScanContainer(ITimelessContentProvider timelessContentProvider)
|
||||
{
|
||||
_timelessContentProvider = timelessContentProvider;
|
||||
_readOnlyExtensions = new ReadOnlyExtensionCollection(Extensions);
|
||||
|
||||
IsLoading = _isLoading.AsObservable();
|
||||
CreatedAt = DateTime.Now;
|
||||
|
||||
_size = new(childContainerSizes => Task.FromResult(childContainerSizes.Sum()));
|
||||
Size = _size.Debounce(TimeSpan.FromSeconds(1));
|
||||
CreatedAt = DateTime.Now;
|
||||
|
||||
Extensions.Add(new EscHandlerContainerExtension(HandleEsc));
|
||||
Extensions.Add(new NonRestorableContainerExtension());
|
||||
Extensions.Add(new RealContainerProviderExtension(() => new(_timelessContentProvider, RealContainer!)));
|
||||
Extensions.Add(new StatusProviderContainerExtension(() => Status));
|
||||
}
|
||||
|
||||
public async Task AddSizeSourceAsync(IDeclarativeProperty<long> sizeElement)
|
||||
@@ -90,4 +101,19 @@ public record SizeScanContainer : ISizeScanContainer, IEscHandlerContainer
|
||||
SizeScanTask.Stop();
|
||||
return Task.FromResult(new ContainerEscapeResult(true));
|
||||
}
|
||||
|
||||
public async Task AddSizeChildAsync(ISizeItem newChild)
|
||||
{
|
||||
SizeItems.Add(newChild);
|
||||
|
||||
if (newChild is ISizeScanContainer newContainer)
|
||||
{
|
||||
ChildContainers.Add(newContainer);
|
||||
}
|
||||
|
||||
await AddSizeSourceAsync(newChild.Size);
|
||||
Items.Add(new AbsolutePath(
|
||||
_timelessContentProvider,
|
||||
newChild));
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
using DeclarativeProperty;
|
||||
using FileTime.Core.Enums;
|
||||
using FileTime.Core.Models;
|
||||
using FileTime.Core.Models.Extensions;
|
||||
using FileTime.Core.Timeline;
|
||||
@@ -13,7 +12,7 @@ public class SizeScanTask : ISizeScanTask
|
||||
private int _processedItems;
|
||||
private ulong _processedItemsTotal;
|
||||
private IContainer _scanSizeOf = null!;
|
||||
private readonly IContainerScanSnapshotProvider _containerScanSnapshotProvider;
|
||||
private readonly IContainerSizeScanProvider _containerSizeScanProvider;
|
||||
private readonly ITimelessContentProvider _timelessContentProvider;
|
||||
private readonly ILogger<SizeScanTask> _logger;
|
||||
private Thread? _sizeScanThread;
|
||||
@@ -24,11 +23,11 @@ public class SizeScanTask : ISizeScanTask
|
||||
public bool IsRunning { get; private set; }
|
||||
|
||||
public SizeScanTask(
|
||||
IContainerScanSnapshotProvider containerScanSnapshotProvider,
|
||||
IContainerSizeScanProvider containerSizeScanProvider,
|
||||
ITimelessContentProvider timelessContentProvider,
|
||||
ILogger<SizeScanTask> logger)
|
||||
{
|
||||
_containerScanSnapshotProvider = containerScanSnapshotProvider;
|
||||
_containerSizeScanProvider = containerSizeScanProvider;
|
||||
_timelessContentProvider = timelessContentProvider;
|
||||
_logger = logger;
|
||||
_containerStatusDebounced = _containerStatus.Debounce(TimeSpan.FromMilliseconds(250));
|
||||
@@ -38,16 +37,16 @@ public class SizeScanTask : ISizeScanTask
|
||||
{
|
||||
_scanSizeOf = scanSizeOf;
|
||||
var name = $"{_searchId++}_{scanSizeOf.Name}";
|
||||
var randomId = ContainerScanProvider.ContentProviderName + Constants.SeparatorChar + name;
|
||||
SizeSizeScanContainer = new SizeScanContainer
|
||||
var randomId = ContainerSizeSizeScanProvider.ContentProviderName + Constants.SeparatorChar + name;
|
||||
SizeSizeScanContainer = new SizeScanContainer(_timelessContentProvider)
|
||||
{
|
||||
Name = name,
|
||||
DisplayName = scanSizeOf.DisplayName,
|
||||
FullName = new FullName(randomId),
|
||||
NativePath = new NativePath(randomId),
|
||||
Parent = new AbsolutePath(_timelessContentProvider, _containerScanSnapshotProvider),
|
||||
Parent = new AbsolutePath(_timelessContentProvider, _containerSizeScanProvider),
|
||||
RealContainer = scanSizeOf,
|
||||
Provider = _containerScanSnapshotProvider,
|
||||
Provider = _containerSizeScanProvider,
|
||||
Status = _containerStatusDebounced,
|
||||
SizeScanTask = this
|
||||
};
|
||||
@@ -87,8 +86,8 @@ public class SizeScanTask : ISizeScanTask
|
||||
IContainer realContainer,
|
||||
ISizeScanContainer sizeScanContainer)
|
||||
{
|
||||
if(_cancelled) return;
|
||||
|
||||
if (_cancelled) return;
|
||||
|
||||
await realContainer.WaitForLoaded();
|
||||
var resolvedItems = new List<IItem>(realContainer.Items.Count);
|
||||
foreach (var item in realContainer.Items)
|
||||
@@ -99,43 +98,36 @@ public class SizeScanTask : ISizeScanTask
|
||||
|
||||
foreach (var element in resolvedItems.OfType<IElement>())
|
||||
{
|
||||
if(_cancelled) return;
|
||||
|
||||
if (_cancelled) return;
|
||||
|
||||
var fileExtension = element.GetExtension<FileExtension>();
|
||||
if (fileExtension?.Size is not { } size) continue;
|
||||
var size = fileExtension?.Size ?? 0;
|
||||
|
||||
var sizeProperty = new DeclarativeProperty<long>(size);
|
||||
|
||||
var childName = sizeScanContainer.FullName!.GetChild(element.Name).Path;
|
||||
await sizeScanContainer.AddSizeSourceAsync(sizeProperty);
|
||||
sizeScanContainer.Items.Add(new AbsolutePath(
|
||||
_timelessContentProvider,
|
||||
PointInTime.Present,
|
||||
new FullName(childName),
|
||||
AbsolutePathType.Element));
|
||||
|
||||
|
||||
var childSearchContainer = new SizeScanElement
|
||||
var childElement = new SizeScanElement
|
||||
{
|
||||
Name = element.Name,
|
||||
DisplayName = element.DisplayName,
|
||||
FullName = new FullName(childName),
|
||||
NativePath = new NativePath(childName),
|
||||
Parent = new AbsolutePath(_timelessContentProvider, sizeScanContainer),
|
||||
Provider = _containerScanSnapshotProvider,
|
||||
Provider = _containerSizeScanProvider,
|
||||
Size = sizeProperty
|
||||
};
|
||||
sizeScanContainer.SizeItems.Add(childSearchContainer);
|
||||
await sizeScanContainer.AddSizeChildAsync(childElement);
|
||||
|
||||
_processedItems++;
|
||||
_processedItemsTotal++;
|
||||
}
|
||||
|
||||
foreach (var childContainer in resolvedItems.OfType<IContainer>())
|
||||
{
|
||||
if(_cancelled) return;
|
||||
|
||||
if (_cancelled) return;
|
||||
|
||||
var childName = sizeScanContainer.FullName!.GetChild(childContainer.Name).Path;
|
||||
var childSearchContainer = new SizeScanContainer
|
||||
var childSearchContainer = new SizeScanContainer(_timelessContentProvider)
|
||||
{
|
||||
Name = childContainer.Name,
|
||||
DisplayName = childContainer.DisplayName,
|
||||
@@ -143,19 +135,12 @@ public class SizeScanTask : ISizeScanTask
|
||||
NativePath = new NativePath(childName),
|
||||
Parent = new AbsolutePath(_timelessContentProvider, sizeScanContainer),
|
||||
RealContainer = childContainer,
|
||||
Provider = _containerScanSnapshotProvider,
|
||||
Provider = _containerSizeScanProvider,
|
||||
Status = _containerStatusDebounced,
|
||||
SizeScanTask = this
|
||||
};
|
||||
|
||||
sizeScanContainer.ChildContainers.Add(childSearchContainer);
|
||||
sizeScanContainer.SizeItems.Add(childSearchContainer);
|
||||
await sizeScanContainer.AddSizeSourceAsync(childSearchContainer.Size);
|
||||
sizeScanContainer.Items.Add(new AbsolutePath(
|
||||
_timelessContentProvider,
|
||||
PointInTime.Present,
|
||||
new FullName(childName),
|
||||
AbsolutePathType.Container));
|
||||
await sizeScanContainer.AddSizeChildAsync(childSearchContainer);
|
||||
|
||||
await TraverseTree(childContainer, childSearchContainer);
|
||||
}
|
||||
|
||||
@@ -9,8 +9,9 @@ public static class Startup
|
||||
{
|
||||
public static IServiceCollection AddContainerSizeScanner(this IServiceCollection services)
|
||||
{
|
||||
services.TryAddSingleton<IContainerScanSnapshotProvider, ContainerScanProvider>();
|
||||
services.AddSingleton<IContentProvider>(sp => sp.GetRequiredService<IContainerScanSnapshotProvider>());
|
||||
services.TryAddSingleton<IContainerSizeScanProvider, ContainerSizeSizeScanProvider>();
|
||||
services.AddSingleton<IContentProvider>(sp => sp.GetRequiredService<IContainerSizeScanProvider>());
|
||||
services.AddSingleton<IExitHandler>(sp => sp.GetRequiredService<IContainerSizeScanProvider>());
|
||||
services.AddTransient<ISizeScanTask, SizeScanTask>();
|
||||
services.AddTransient<IItemPreviewProvider, PreviewProvider>();
|
||||
return services;
|
||||
|
||||
@@ -8,25 +8,24 @@ public enum ItemNotFoundExceptionType
|
||||
FullName,
|
||||
NativePath
|
||||
}
|
||||
|
||||
public class ItemNotFoundException : Exception
|
||||
{
|
||||
public string Path { get; }
|
||||
public ItemNotFoundExceptionType Type { get; } = ItemNotFoundExceptionType.Raw;
|
||||
|
||||
public ItemNotFoundException(string path)
|
||||
public ItemNotFoundException(string path) : base("Item not found " + path)
|
||||
{
|
||||
Path = path;
|
||||
}
|
||||
|
||||
public ItemNotFoundException(FullName path)
|
||||
public ItemNotFoundException(FullName path) : this(path.Path)
|
||||
{
|
||||
Path = path.Path;
|
||||
Type = ItemNotFoundExceptionType.FullName;
|
||||
}
|
||||
|
||||
public ItemNotFoundException(NativePath path)
|
||||
public ItemNotFoundException(NativePath path) : this(path.Path)
|
||||
{
|
||||
Path = path.Path;
|
||||
Type = ItemNotFoundExceptionType.NativePath;
|
||||
}
|
||||
}
|
||||
@@ -10,4 +10,5 @@ public interface IModalService
|
||||
void OpenModal(IModalViewModel modalToOpen);
|
||||
void CloseModal(IModalViewModel modalToClose);
|
||||
T OpenModal<T>() where T : IModalViewModel;
|
||||
event EventHandler? AllModalClosed;
|
||||
}
|
||||
@@ -2,6 +2,7 @@ using System.Text.Json;
|
||||
using FileTime.App.Core.Models;
|
||||
using FileTime.App.Core.ViewModels;
|
||||
using FileTime.Core.Models;
|
||||
using FileTime.Core.Models.Extensions;
|
||||
using FileTime.Core.Services;
|
||||
using FileTime.Core.Timeline;
|
||||
using FileTime.Providers.Local;
|
||||
@@ -202,7 +203,14 @@ public class TabPersistenceService : ITabPersistenceService
|
||||
{
|
||||
var currentLocation = tab.CurrentLocation.Value;
|
||||
if (currentLocation is null) continue;
|
||||
tabStates.Add(new TabState(currentLocation.FullName!.Path, tab.TabNumber));
|
||||
var path = currentLocation.FullName!.Path;
|
||||
|
||||
if (currentLocation.GetExtension<RealContainerProviderExtension>()?.RealContainer() is { } realPath)
|
||||
{
|
||||
path = realPath.Path.Path;
|
||||
}
|
||||
|
||||
tabStates.Add(new TabState(path, tab.TabNumber));
|
||||
}
|
||||
|
||||
return new TabStates(
|
||||
|
||||
@@ -13,6 +13,7 @@ using FileTime.Core.Services;
|
||||
using FileTime.Core.Timeline;
|
||||
using FileTime.Providers.Local;
|
||||
using InitableService;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace FileTime.App.Core.Services.UserCommandHandler;
|
||||
|
||||
@@ -27,6 +28,7 @@ public class NavigationUserCommandHandlerService : UserCommandHandlerServiceBase
|
||||
private readonly IUserCommunicationService _userCommunicationService;
|
||||
private readonly IFrequencyNavigationService _frequencyNavigationService;
|
||||
private readonly ICommandPaletteService _commandPaletteService;
|
||||
private readonly ILogger<NavigationUserCommandHandlerService> _logger;
|
||||
private ITabViewModel? _selectedTab;
|
||||
private IDeclarativeProperty<IContainer?>? _currentLocation;
|
||||
private IDeclarativeProperty<IItemViewModel?>? _currentSelectedItem;
|
||||
@@ -41,7 +43,8 @@ public class NavigationUserCommandHandlerService : UserCommandHandlerServiceBase
|
||||
ITimelessContentProvider timelessContentProvider,
|
||||
IUserCommunicationService userCommunicationService,
|
||||
IFrequencyNavigationService frequencyNavigationService,
|
||||
ICommandPaletteService commandPaletteService) : base(appState)
|
||||
ICommandPaletteService commandPaletteService,
|
||||
ILogger<NavigationUserCommandHandlerService> logger) : base(appState)
|
||||
{
|
||||
_appState = appState;
|
||||
_serviceProvider = serviceProvider;
|
||||
@@ -51,6 +54,7 @@ public class NavigationUserCommandHandlerService : UserCommandHandlerServiceBase
|
||||
_userCommunicationService = userCommunicationService;
|
||||
_frequencyNavigationService = frequencyNavigationService;
|
||||
_commandPaletteService = commandPaletteService;
|
||||
_logger = logger;
|
||||
|
||||
SaveSelectedTab(t => _selectedTab = t);
|
||||
SaveCurrentSelectedItem(i => _currentSelectedItem = i);
|
||||
@@ -332,11 +336,23 @@ public class NavigationUserCommandHandlerService : UserCommandHandlerServiceBase
|
||||
}
|
||||
else if (tabViewModel == null)
|
||||
{
|
||||
var newLocation = _currentLocation?.Value?.FullName is { } fullName
|
||||
? (IContainer) await _timelessContentProvider.GetItemByFullNameAsync(fullName, PointInTime.Present)
|
||||
: _localContentProvider;
|
||||
IContainer? newLocation = null;
|
||||
|
||||
var tab = await _serviceProvider.GetAsyncInitableResolver<IContainer>(newLocation)
|
||||
try
|
||||
{
|
||||
newLocation = _currentLocation?.Value?.FullName is { } fullName
|
||||
? (IContainer) await _timelessContentProvider.GetItemByFullNameAsync(fullName, PointInTime.Present)
|
||||
: _localContentProvider;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
var fullName = _currentLocation?.Value?.FullName?.Path ?? "unknown";
|
||||
_logger.LogError(ex, "Could not resolve container while switching to tab {TabNumber} to path {FullName}", number, fullName);
|
||||
}
|
||||
|
||||
newLocation ??= _localContentProvider;
|
||||
|
||||
var tab = await _serviceProvider.GetAsyncInitableResolver(newLocation)
|
||||
.GetRequiredServiceAsync<ITab>();
|
||||
var newTabViewModel = _serviceProvider.GetInitableResolver(tab, number).GetRequiredService<ITabViewModel>();
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ public class ToolUserCommandHandlerService : UserCommandHandlerServiceBase
|
||||
private readonly ITimelessContentProvider _timelessContentProvider;
|
||||
private readonly IUserCommandHandlerService _userCommandHandlerService;
|
||||
private readonly IContentAccessorFactory _contentAccessorFactory;
|
||||
private readonly IContainerScanSnapshotProvider _containerScanSnapshotProvider;
|
||||
private readonly IContainerSizeScanProvider _containerSizeScanProvider;
|
||||
private IDeclarativeProperty<IContainer?>? _currentLocation;
|
||||
private IDeclarativeProperty<IItemViewModel?>? _currentSelectedItem;
|
||||
private ITabViewModel? _currentSelectedTab;
|
||||
@@ -36,7 +36,7 @@ public class ToolUserCommandHandlerService : UserCommandHandlerServiceBase
|
||||
ITimelessContentProvider timelessContentProvider,
|
||||
IUserCommandHandlerService userCommandHandlerService,
|
||||
IContentAccessorFactory contentAccessorFactory,
|
||||
IContainerScanSnapshotProvider containerScanSnapshotProvider) : base(appState)
|
||||
IContainerSizeScanProvider containerSizeScanProvider) : base(appState)
|
||||
{
|
||||
_systemClipboardService = systemClipboardService;
|
||||
_userCommunicationService = userCommunicationService;
|
||||
@@ -45,7 +45,7 @@ public class ToolUserCommandHandlerService : UserCommandHandlerServiceBase
|
||||
_timelessContentProvider = timelessContentProvider;
|
||||
_userCommandHandlerService = userCommandHandlerService;
|
||||
_contentAccessorFactory = contentAccessorFactory;
|
||||
_containerScanSnapshotProvider = containerScanSnapshotProvider;
|
||||
_containerSizeScanProvider = containerSizeScanProvider;
|
||||
SaveCurrentLocation(l => _currentLocation = l);
|
||||
SaveCurrentSelectedItem(i => _currentSelectedItem = i);
|
||||
SaveSelectedTab(t => _currentSelectedTab = t);
|
||||
@@ -65,7 +65,7 @@ public class ToolUserCommandHandlerService : UserCommandHandlerServiceBase
|
||||
{
|
||||
if (_currentLocation?.Value is null) return;
|
||||
|
||||
var searchTask = _containerScanSnapshotProvider.StartSizeScan(_currentLocation.Value);
|
||||
var searchTask = _containerSizeScanProvider.StartSizeScan(_currentLocation.Value);
|
||||
var openContainerCommand = new OpenContainerCommand(new AbsolutePath(_timelessContentProvider, searchTask.SizeSizeScanContainer));
|
||||
await _userCommandHandlerService.HandleCommandAsync(openContainerCommand);
|
||||
}
|
||||
|
||||
@@ -2,11 +2,9 @@ using System.Collections.ObjectModel;
|
||||
using System.Reactive.Linq;
|
||||
using System.Reactive.Subjects;
|
||||
using DeclarativeProperty;
|
||||
using DynamicData;
|
||||
using FileTime.App.Core.Models.Enums;
|
||||
using FileTime.App.Core.ViewModels.Timeline;
|
||||
using FileTime.Core.Models;
|
||||
using FileTime.Core.Models.ContainerTraits;
|
||||
using FileTime.Core.Models.Extensions;
|
||||
using MvvmGen;
|
||||
using MoreLinq;
|
||||
|
||||
@@ -48,7 +46,7 @@ public abstract partial class AppStateBase : IAppState
|
||||
ContainerStatus = SelectedTab
|
||||
.Map(t => t?.CurrentLocation)
|
||||
.Switch()
|
||||
.Map(c => c is IStatusProviderContainer statusProvider ? statusProvider.Status : null)
|
||||
.Map(c => c?.GetExtension<StatusProviderContainerExtension>()?.GetStatusProperty())
|
||||
.Switch();
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ using FileTime.App.Core.Services;
|
||||
using FileTime.App.FrequencyNavigation.Models;
|
||||
using FileTime.App.FrequencyNavigation.ViewModels;
|
||||
using FileTime.Core.Models;
|
||||
using FileTime.Core.Models.Extensions;
|
||||
using FileTime.Core.Services;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using PropertyChanged.SourceGenerator;
|
||||
@@ -38,9 +39,16 @@ public partial class FrequencyNavigationService : IFrequencyNavigationService, I
|
||||
tabEvents.LocationChanged += OnTabLocationChanged;
|
||||
}
|
||||
|
||||
void OnTabLocationChanged(object? sender, TabLocationChanged e)
|
||||
async void OnTabLocationChanged(object? sender, TabLocationChanged e)
|
||||
{
|
||||
IncreaseContainerScore(e.Location);
|
||||
try
|
||||
{
|
||||
await IncreaseContainerScore(e.Location);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Fatal error while increasing container score");
|
||||
}
|
||||
}
|
||||
|
||||
public void OpenNavigationWindow()
|
||||
@@ -59,12 +67,16 @@ public partial class FrequencyNavigationService : IFrequencyNavigationService, I
|
||||
}
|
||||
}
|
||||
|
||||
private async void IncreaseContainerScore(FullName containerName)
|
||||
private async Task IncreaseContainerScore(IContainer container)
|
||||
{
|
||||
await _saveLock.WaitAsync();
|
||||
try
|
||||
{
|
||||
var containerNameString = containerName.Path;
|
||||
if (container.GetExtension<NonRestorableContainerExtension>() is not null) return;
|
||||
|
||||
var containerNameString = container.FullName?.Path;
|
||||
if (containerNameString is null) return;
|
||||
|
||||
if (_containerScores.ContainsKey(containerNameString))
|
||||
{
|
||||
_containerScores[containerNameString].Score++;
|
||||
@@ -89,6 +101,7 @@ public partial class FrequencyNavigationService : IFrequencyNavigationService, I
|
||||
if (TryAgeContainerScores() || DateTime.Now - _lastSave > TimeSpan.FromMinutes(5))
|
||||
{
|
||||
}
|
||||
|
||||
//TODO: move to if above
|
||||
await SaveStateAsync();
|
||||
}
|
||||
@@ -113,7 +126,7 @@ public partial class FrequencyNavigationService : IFrequencyNavigationService, I
|
||||
var itemsToRemove = new List<string>();
|
||||
foreach (var container in _containerScores)
|
||||
{
|
||||
var newScore = (int)Math.Floor(container.Value.Score * 0.9);
|
||||
var newScore = (int) Math.Floor(container.Value.Score * 0.9);
|
||||
if (newScore > 0)
|
||||
{
|
||||
container.Value.Score = newScore;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using FileTime.Core.Enums;
|
||||
using FileTime.Core.Models;
|
||||
using FileTime.Core.Models.Extensions;
|
||||
using FileTime.Core.Timeline;
|
||||
|
||||
namespace FileTime.App.Search;
|
||||
@@ -38,7 +39,8 @@ public class SearchTask : ISearchTask
|
||||
|
||||
var extensions = new ExtensionCollection
|
||||
{
|
||||
new SearchExtension(this)
|
||||
new SearchExtension(this),
|
||||
new RealContainerProviderExtension(() => new AbsolutePath(_timelessContentProvider, baseContainer))
|
||||
};
|
||||
_container = new Container(
|
||||
baseContainer.Name,
|
||||
@@ -102,9 +104,9 @@ public class SearchTask : ISearchTask
|
||||
var childName = _container.FullName.GetChild(itemPath.Path.GetName());
|
||||
_realFullNames.Add(childName, itemPath.Path);
|
||||
_items.Add(new AbsolutePath(
|
||||
_timelessContentProvider,
|
||||
PointInTime.Present,
|
||||
childName,
|
||||
_timelessContentProvider,
|
||||
PointInTime.Present,
|
||||
childName,
|
||||
AbsolutePathType.Container
|
||||
));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user