File scoped namespace

This commit is contained in:
2022-05-07 19:40:54 +02:00
parent b161ded92e
commit 9bf95ebe4e
126 changed files with 2562 additions and 2598 deletions

View File

@@ -4,64 +4,63 @@ using DynamicData;
using FileTime.Core.Enums;
using FileTime.Core.Models;
namespace FileTime.Core.Services
namespace FileTime.Core.Services;
public abstract class ContentProviderBase : IContentProvider
{
public abstract class ContentProviderBase : IContentProvider
protected BehaviorSubject<IObservable<IChangeSet<IAbsolutePath>>?> Items { get; } = new (null);
IObservable<IObservable<IChangeSet<IAbsolutePath>>?> IContainer.Items => Items;
public string Name { get; }
public string DisplayName { get; }
public FullName? FullName => null;
public NativePath? NativePath => null;
public bool IsHidden => false;
public bool IsExists => true;
public SupportsDelete CanDelete => SupportsDelete.False;
public bool CanRename => false;
public IContentProvider Provider => this;
public IAbsolutePath? Parent => null;
public DateTime? CreatedAt => null;
public string? Attributes => null;
protected BehaviorSubject<bool> IsLoading { get; } = new(false);
IObservable<bool> IContainer.IsLoading => IsLoading.AsObservable();
public AbsolutePathType Type => AbsolutePathType.Container;
public IObservable<IEnumerable<Exception>> Exceptions => Observable.Return(Enumerable.Empty<Exception>());
protected ContentProviderBase(string name)
{
protected BehaviorSubject<IObservable<IChangeSet<IAbsolutePath>>?> Items { get; } = new (null);
IObservable<IObservable<IChangeSet<IAbsolutePath>>?> IContainer.Items => Items;
public string Name { get; }
public string DisplayName { get; }
public FullName? FullName => null;
public NativePath? NativePath => null;
public bool IsHidden => false;
public bool IsExists => true;
public SupportsDelete CanDelete => SupportsDelete.False;
public bool CanRename => false;
public IContentProvider Provider => this;
public IAbsolutePath? Parent => null;
public DateTime? CreatedAt => null;
public string? Attributes => null;
protected BehaviorSubject<bool> IsLoading { get; } = new(false);
IObservable<bool> IContainer.IsLoading => IsLoading.AsObservable();
public AbsolutePathType Type => AbsolutePathType.Container;
public IObservable<IEnumerable<Exception>> Exceptions => Observable.Return(Enumerable.Empty<Exception>());
protected ContentProviderBase(string name)
{
DisplayName = Name = name;
}
public virtual Task OnEnter() => Task.CompletedTask;
public virtual async Task<IItem> GetItemByFullNameAsync(
FullName fullName,
bool forceResolve = false,
AbsolutePathType forceResolvePathType = AbsolutePathType.Unknown,
ItemInitializationSettings itemInitializationSettings = default)
=> await GetItemByNativePathAsync(GetNativePath(fullName), forceResolve, forceResolvePathType, itemInitializationSettings);
public abstract Task<IItem> GetItemByNativePathAsync(
NativePath nativePath,
bool forceResolve = false,
AbsolutePathType forceResolvePathType = AbsolutePathType.Unknown,
ItemInitializationSettings itemInitializationSettings = default);
public abstract Task<List<IAbsolutePath>> GetItemsByContainerAsync(FullName fullName);
public abstract NativePath GetNativePath(FullName fullName);
DisplayName = Name = name;
}
public virtual Task OnEnter() => Task.CompletedTask;
public virtual async Task<IItem> GetItemByFullNameAsync(
FullName fullName,
bool forceResolve = false,
AbsolutePathType forceResolvePathType = AbsolutePathType.Unknown,
ItemInitializationSettings itemInitializationSettings = default)
=> await GetItemByNativePathAsync(GetNativePath(fullName), forceResolve, forceResolvePathType, itemInitializationSettings);
public abstract Task<IItem> GetItemByNativePathAsync(
NativePath nativePath,
bool forceResolve = false,
AbsolutePathType forceResolvePathType = AbsolutePathType.Unknown,
ItemInitializationSettings itemInitializationSettings = default);
public abstract Task<List<IAbsolutePath>> GetItemsByContainerAsync(FullName fullName);
public abstract NativePath GetNativePath(FullName fullName);
}

View File

@@ -6,6 +6,10 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<PropertyGroup>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.Interactive.Async" Version="6.0.1" />
<PackageReference Include="System.Linq.Async" Version="6.0.1" />

View File

@@ -3,24 +3,24 @@ using System.Reactive.Subjects;
using DynamicData;
using FileTime.Core.Models;
namespace FileTime.Core.Services
namespace FileTime.Core.Services;
public class Tab : ITab
{
public class Tab : ITab
private readonly BehaviorSubject<IContainer?> _currentLocation = new(null);
private readonly BehaviorSubject<IAbsolutePath?> _currentSelectedItem = new(null);
private readonly List<ItemsTransformator> _transformators = new();
private IAbsolutePath? _currentSelectedItemCached;
public IObservable<IContainer?> CurrentLocation { get; }
public IObservable<IObservable<IChangeSet<IItem>>?> CurrentItems { get; }
public IObservable<IAbsolutePath?> CurrentSelectedItem { get; }
public Tab()
{
private readonly BehaviorSubject<IContainer?> _currentLocation = new(null);
private readonly BehaviorSubject<IAbsolutePath?> _currentSelectedItem = new(null);
private readonly List<ItemsTransformator> _transformators = new();
private IAbsolutePath? _currentSelectedItemCached;
public IObservable<IContainer?> CurrentLocation { get; }
public IObservable<IObservable<IChangeSet<IItem>>?> CurrentItems { get; }
public IObservable<IAbsolutePath?> CurrentSelectedItem { get; }
public Tab()
{
CurrentLocation = _currentLocation.DistinctUntilChanged().Publish(null).RefCount();
CurrentItems =
Observable.Merge(
CurrentLocation = _currentLocation.DistinctUntilChanged().Publish(null).RefCount();
CurrentItems =
Observable.Merge(
CurrentLocation
.Where(c => c is not null)
.Select(c => c!.Items)
@@ -33,13 +33,13 @@ namespace FileTime.Core.Services
.Publish((IObservable<IChangeSet<IItem>>?)null)
.RefCount();
CurrentSelectedItem =
Observable.CombineLatest(
CurrentSelectedItem =
Observable.CombineLatest(
CurrentItems
.Select(c =>
c == null
? Observable.Return<IReadOnlyCollection<IItem>?>(null)
: c.ToCollection()
? Observable.Return<IReadOnlyCollection<IItem>?>(null)
: c.ToCollection()
)
.Switch(),
_currentSelectedItem,
@@ -55,41 +55,40 @@ namespace FileTime.Core.Services
.Publish(null)
.RefCount();
CurrentSelectedItem.Subscribe(s =>
{
_currentSelectedItemCached = s;
_currentSelectedItem.OnNext(s);
});
}
private async Task<IItem> MapItem(IAbsolutePath item) => await item.ResolveAsync(true);
public void Init(IContainer currentLocation)
CurrentSelectedItem.Subscribe(s =>
{
_currentLocation.OnNext(currentLocation);
}
_currentSelectedItemCached = s;
_currentSelectedItem.OnNext(s);
});
}
private static IAbsolutePath? GetSelectedItemByItems(IEnumerable<IItem> items)
{
//TODO:
return new AbsolutePath(items.First());
}
private async Task<IItem> MapItem(IAbsolutePath item) => await item.ResolveAsync(true);
public void SetCurrentLocation(IContainer newLocation) => _currentLocation.OnNext(newLocation);
public void Init(IContainer currentLocation)
{
_currentLocation.OnNext(currentLocation);
}
public void SetSelectedItem(IAbsolutePath newSelectedItem) => _currentSelectedItem.OnNext(newSelectedItem);
private static IAbsolutePath? GetSelectedItemByItems(IEnumerable<IItem> items)
{
//TODO:
return new AbsolutePath(items.First());
}
public void AddSelectedItemsTransformator(ItemsTransformator transformator) => _transformators.Add(transformator);
public void RemoveSelectedItemsTransformator(ItemsTransformator transformator) => _transformators.Remove(transformator);
public void RemoveSelectedItemsTransformatorByName(string name) => _transformators.RemoveAll(t => t.Name == name);
public void SetCurrentLocation(IContainer newLocation) => _currentLocation.OnNext(newLocation);
public async Task OpenSelected()
{
if (_currentSelectedItemCached == null) return;
var resolvedSelectedItem = await _currentSelectedItemCached.ContentProvider.GetItemByFullNameAsync(_currentSelectedItemCached.Path);
public void SetSelectedItem(IAbsolutePath newSelectedItem) => _currentSelectedItem.OnNext(newSelectedItem);
if (resolvedSelectedItem is not IContainer resolvedContainer) return;
SetCurrentLocation(resolvedContainer);
}
public void AddSelectedItemsTransformator(ItemsTransformator transformator) => _transformators.Add(transformator);
public void RemoveSelectedItemsTransformator(ItemsTransformator transformator) => _transformators.Remove(transformator);
public void RemoveSelectedItemsTransformatorByName(string name) => _transformators.RemoveAll(t => t.Name == name);
public async Task OpenSelected()
{
if (_currentSelectedItemCached == null) return;
var resolvedSelectedItem = await _currentSelectedItemCached.ContentProvider.GetItemByFullNameAsync(_currentSelectedItemCached.Path);
if (resolvedSelectedItem is not IContainer resolvedContainer) return;
SetCurrentLocation(resolvedContainer);
}
}