using System; using AsyncEvent; using FileTime.Core.Models; namespace FileTime.Core.Providers { public class TopContainer : IContainer { private readonly List _contentProviders; private readonly IReadOnlyList? _containers; private readonly IReadOnlyList? _items; private readonly IReadOnlyList? _elements = new List().AsReadOnly(); #pragma warning disable CS8603 // Possible null reference return. public string Name => null; #pragma warning restore CS8603 // Possible null reference return. public string? FullName => null; public bool IsHidden => false; public bool IsLoaded => true; #pragma warning disable CS8603 // Possible null reference return. public IContentProvider Provider => null; #pragma warning restore CS8603 // Possible null reference return. public bool CanDelete => false; public bool CanRename => false; public AsyncEventHandler Refreshed { get; } = new(); public IReadOnlyList Exceptions { get; } = new List().AsReadOnly(); public TopContainer(IEnumerable contentProviders) { _contentProviders = new List(contentProviders); _containers = _contentProviders.AsReadOnly(); _items = _containers.Cast().ToList().AsReadOnly(); foreach (var contentProvider in contentProviders) { contentProvider.SetParent(this); } } public Task CreateContainer(string name) => throw new NotImplementedException(); public Task CreateElement(string name) => throw new NotImplementedException(); public Task Delete() => throw new NotImplementedException(); public Task GetByPath(string path) => throw new NotImplementedException(); public IContainer? GetParent() => null; public Task IsExists(string name) => throw new NotImplementedException(); public async Task Refresh() => await Refreshed.InvokeAsync(this, AsyncEventArgs.Empty); public Task?> GetItems(CancellationToken token = default) => Task.FromResult(_items); public Task?> GetContainers(CancellationToken token = default) => Task.FromResult(_containers); public Task?> GetElements(CancellationToken token = default) => Task.FromResult(_elements); public Task Clone() => Task.FromResult((IContainer)this); public Task Rename(string newName) => throw new NotSupportedException(); public Task CanOpen() => Task.FromResult(true); } }