Element preview
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
using System.Collections;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace FileTime.Core.Models;
|
||||
|
||||
public class ExtensionCollection : IEnumerable<object>
|
||||
{
|
||||
private readonly List<object> _extensions = new();
|
||||
|
||||
public ExtensionCollection()
|
||||
{
|
||||
}
|
||||
|
||||
public ExtensionCollection(IEnumerable<object> objects)
|
||||
{
|
||||
foreach (var obj in objects)
|
||||
{
|
||||
AddSafe(obj);
|
||||
}
|
||||
}
|
||||
|
||||
private void AddSafe(object obj)
|
||||
{
|
||||
var objType = obj.GetType();
|
||||
if (_extensions.Any(i => i.GetType() == objType))
|
||||
throw new ArgumentException($"Collection already contains an item with type {objType.FullName}");
|
||||
|
||||
_extensions.Add(obj);
|
||||
}
|
||||
|
||||
public void Add<T>([DisallowNull] T obj, [CallerArgumentExpression("obj")] string? paramName = null)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(obj, paramName);
|
||||
AddSafe(obj);
|
||||
}
|
||||
|
||||
public void Remove<T>()
|
||||
{
|
||||
_extensions.RemoveAll(i => i is T);
|
||||
}
|
||||
|
||||
public ReadOnlyExtensionCollection AsReadOnly() => new ReadOnlyExtensionCollection(this);
|
||||
|
||||
public IEnumerator<object> GetEnumerator() => _extensions.GetEnumerator();
|
||||
IEnumerator IEnumerable.GetEnumerator() => _extensions.GetEnumerator();
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
namespace FileTime.Core.Models;
|
||||
|
||||
public interface IFileElement : IElement
|
||||
{
|
||||
long Size { get; }
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
using System.Reactive.Linq;
|
||||
using FileTime.Core.Enums;
|
||||
using FileTime.Core.Services;
|
||||
|
||||
@@ -19,4 +20,7 @@ public interface IItem
|
||||
string? Attributes { get; }
|
||||
AbsolutePathType Type { get; }
|
||||
IObservable<IEnumerable<Exception>> Exceptions { get; }
|
||||
ReadOnlyExtensionCollection Extensions { get; }
|
||||
|
||||
T? GetExtension<T>() => (T?)Extensions.FirstOrDefault(i => i is T);
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using System.Collections;
|
||||
|
||||
namespace FileTime.Core.Models;
|
||||
|
||||
public class ReadOnlyExtensionCollection : IEnumerable<object>
|
||||
{
|
||||
private readonly ExtensionCollection _collection;
|
||||
|
||||
public ReadOnlyExtensionCollection(ExtensionCollection collection)
|
||||
{
|
||||
_collection = collection;
|
||||
}
|
||||
|
||||
public IEnumerator<object> GetEnumerator() => _collection.GetEnumerator();
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator() => _collection.GetEnumerator();
|
||||
}
|
||||
@@ -20,4 +20,6 @@ public interface IContentProvider : IContainer, IOnContainerEnter
|
||||
|
||||
Task<List<IAbsolutePath>> GetItemsByContainerAsync(FullName fullName);
|
||||
NativePath GetNativePath(FullName fullName);
|
||||
|
||||
Task<byte[]?> GetContentAsync(IElement element, int? maxLength = null, CancellationToken cancellationToken = default);
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Reactive.Linq;
|
||||
using System.Reactive.Subjects;
|
||||
using DynamicData;
|
||||
@@ -20,6 +21,7 @@ public record Container(
|
||||
string? Attributes,
|
||||
IContentProvider Provider,
|
||||
IObservable<IEnumerable<Exception>> Exceptions,
|
||||
ReadOnlyExtensionCollection Extensions,
|
||||
IObservable<IObservable<IChangeSet<IAbsolutePath>>?> Items) : IContainer
|
||||
{
|
||||
BehaviorSubject<bool> IsLoading { get; } = new BehaviorSubject<bool>(false);
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using FileTime.Core.Enums;
|
||||
using FileTime.Core.Services;
|
||||
|
||||
@@ -16,7 +17,8 @@ public record Element(
|
||||
bool CanRename,
|
||||
string? Attributes,
|
||||
IContentProvider Provider,
|
||||
IObservable<IEnumerable<Exception>> Exceptions) : IElement
|
||||
IObservable<IEnumerable<Exception>> Exceptions,
|
||||
ReadOnlyExtensionCollection Extensions) : IElement
|
||||
{
|
||||
public AbsolutePathType Type => AbsolutePathType.Element;
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
using FileTime.Core.Enums;
|
||||
using FileTime.Core.Services;
|
||||
|
||||
namespace FileTime.Core.Models;
|
||||
|
||||
public record FileElement(
|
||||
string Name,
|
||||
string DisplayName,
|
||||
FullName FullName,
|
||||
NativePath NativePath,
|
||||
IAbsolutePath? Parent,
|
||||
bool IsHidden,
|
||||
bool IsExists,
|
||||
DateTime? CreatedAt,
|
||||
SupportsDelete CanDelete,
|
||||
bool CanRename,
|
||||
string? Attributes,
|
||||
IContentProvider Provider,
|
||||
IObservable<IEnumerable<Exception>> Exceptions,
|
||||
long Size)
|
||||
: Element(
|
||||
Name,
|
||||
DisplayName,
|
||||
FullName,
|
||||
NativePath,
|
||||
Parent,
|
||||
IsHidden,
|
||||
IsExists,
|
||||
CreatedAt,
|
||||
CanDelete,
|
||||
CanRename,
|
||||
Attributes,
|
||||
Provider,
|
||||
Exceptions
|
||||
), IFileElement;
|
||||
@@ -1,3 +1,4 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Reactive.Linq;
|
||||
using System.Reactive.Subjects;
|
||||
using DynamicData;
|
||||
@@ -8,7 +9,10 @@ namespace FileTime.Core.Services;
|
||||
|
||||
public abstract class ContentProviderBase : IContentProvider
|
||||
{
|
||||
private readonly ReadOnlyExtensionCollection _extensions;
|
||||
|
||||
protected BehaviorSubject<IObservable<IChangeSet<IAbsolutePath>>?> Items { get; } = new(null);
|
||||
protected ExtensionCollection Extensions { get; }
|
||||
|
||||
IObservable<IObservable<IChangeSet<IAbsolutePath>>?> IContainer.Items => Items;
|
||||
|
||||
@@ -44,10 +48,14 @@ public abstract class ContentProviderBase : IContentProvider
|
||||
|
||||
public IObservable<IEnumerable<Exception>> Exceptions => Observable.Return(Enumerable.Empty<Exception>());
|
||||
|
||||
ReadOnlyExtensionCollection IItem.Extensions => _extensions;
|
||||
|
||||
protected ContentProviderBase(string name)
|
||||
{
|
||||
DisplayName = Name = name;
|
||||
FullName = new FullName(name);
|
||||
Extensions = new ExtensionCollection();
|
||||
_extensions = Extensions.AsReadOnly();
|
||||
}
|
||||
|
||||
public virtual Task OnEnter() => Task.CompletedTask;
|
||||
@@ -57,7 +65,8 @@ public abstract class ContentProviderBase : IContentProvider
|
||||
bool forceResolve = false,
|
||||
AbsolutePathType forceResolvePathType = AbsolutePathType.Unknown,
|
||||
ItemInitializationSettings itemInitializationSettings = default)
|
||||
=> await GetItemByNativePathAsync(GetNativePath(fullName), forceResolve, forceResolvePathType, itemInitializationSettings);
|
||||
=> await GetItemByNativePathAsync(GetNativePath(fullName), forceResolve, forceResolvePathType,
|
||||
itemInitializationSettings);
|
||||
|
||||
public abstract Task<IItem> GetItemByNativePathAsync(
|
||||
NativePath nativePath,
|
||||
@@ -67,4 +76,8 @@ public abstract class ContentProviderBase : IContentProvider
|
||||
|
||||
public abstract Task<List<IAbsolutePath>> GetItemsByContainerAsync(FullName fullName);
|
||||
public abstract NativePath GetNativePath(FullName fullName);
|
||||
|
||||
public abstract Task<byte[]?> GetContentAsync(IElement element,
|
||||
int? maxLength = null,
|
||||
CancellationToken cancellationToken = default);
|
||||
}
|
||||
Reference in New Issue
Block a user