Cleanup
This commit is contained in:
17
src/Core/FileTime.Core/Models/AbsolutePath.cs
Normal file
17
src/Core/FileTime.Core/Models/AbsolutePath.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using FileTime.Core.Providers;
|
||||
|
||||
namespace FileTime.Core.Models
|
||||
{
|
||||
public class AbsolutePath : IAbsolutePath
|
||||
{
|
||||
public IContentProvider ContentProvider { get; }
|
||||
|
||||
public string Path { get; }
|
||||
|
||||
public AbsolutePath(IContentProvider contentProvider, string path)
|
||||
{
|
||||
ContentProvider = contentProvider;
|
||||
Path = path;
|
||||
}
|
||||
}
|
||||
}
|
||||
7
src/Core/FileTime.Core/Models/Constants.cs
Normal file
7
src/Core/FileTime.Core/Models/Constants.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace FileTime.Core.Models
|
||||
{
|
||||
public static class Constants
|
||||
{
|
||||
public const char SeparatorChar = '/';
|
||||
}
|
||||
}
|
||||
10
src/Core/FileTime.Core/Models/IAbsolutePath.cs
Normal file
10
src/Core/FileTime.Core/Models/IAbsolutePath.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using FileTime.Core.Providers;
|
||||
|
||||
namespace FileTime.Core.Models
|
||||
{
|
||||
public interface IAbsolutePath
|
||||
{
|
||||
IContentProvider ContentProvider { get; }
|
||||
string Path { get; }
|
||||
}
|
||||
}
|
||||
19
src/Core/FileTime.Core/Models/IContainer.cs
Normal file
19
src/Core/FileTime.Core/Models/IContainer.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
namespace FileTime.Core.Models
|
||||
{
|
||||
public interface IContainer : IItem
|
||||
{
|
||||
IReadOnlyList<IItem> Items { get; }
|
||||
IReadOnlyList<IContainer> Containers { get; }
|
||||
IReadOnlyList<IElement> Elements { get; }
|
||||
|
||||
void Refresh();
|
||||
IContainer? GetParent();
|
||||
IItem? GetByPath(string path);
|
||||
IContainer CreateContainer(string name);
|
||||
IElement CreateElement(string name);
|
||||
|
||||
bool IsExists(string name);
|
||||
|
||||
event EventHandler? Refreshed;
|
||||
}
|
||||
}
|
||||
8
src/Core/FileTime.Core/Models/IElement.cs
Normal file
8
src/Core/FileTime.Core/Models/IElement.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace FileTime.Core.Models
|
||||
{
|
||||
public interface IElement : IItem
|
||||
{
|
||||
bool IsSpecial { get; }
|
||||
string GetPrimaryAttributeText();
|
||||
}
|
||||
}
|
||||
13
src/Core/FileTime.Core/Models/IItem.cs
Normal file
13
src/Core/FileTime.Core/Models/IItem.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using FileTime.Core.Providers;
|
||||
|
||||
namespace FileTime.Core.Models
|
||||
{
|
||||
public interface IItem
|
||||
{
|
||||
string Name { get; }
|
||||
string? FullName { get; }
|
||||
bool IsHidden { get; }
|
||||
IContentProvider Provider { get; }
|
||||
void Delete();
|
||||
}
|
||||
}
|
||||
122
src/Core/FileTime.Core/Models/VirtualContainer.cs
Normal file
122
src/Core/FileTime.Core/Models/VirtualContainer.cs
Normal file
@@ -0,0 +1,122 @@
|
||||
using FileTime.Core.Providers;
|
||||
|
||||
namespace FileTime.Core.Models
|
||||
{
|
||||
public class VirtualContainer : IContainer
|
||||
{
|
||||
private readonly List<Func<IEnumerable<IContainer>, IEnumerable<IContainer>>> _containerTransformators;
|
||||
private readonly List<Func<IEnumerable<IElement>, IEnumerable<IElement>>> _elementTransformators;
|
||||
|
||||
public IContainer BaseContainer { get; }
|
||||
|
||||
public bool IsPermanent { get; }
|
||||
public bool IsTransitive { get; }
|
||||
public string? VirtualContainerName { get; }
|
||||
public IReadOnlyList<IItem> Items { get; private set; }
|
||||
|
||||
public IReadOnlyList<IContainer> Containers { get; private set; }
|
||||
|
||||
public IReadOnlyList<IElement> Elements { get; private set; }
|
||||
|
||||
public string Name => BaseContainer.Name;
|
||||
|
||||
public string? FullName => BaseContainer.FullName;
|
||||
|
||||
public bool IsHidden => BaseContainer.IsHidden;
|
||||
|
||||
public IContentProvider Provider => BaseContainer.Provider;
|
||||
|
||||
public event EventHandler? Refreshed
|
||||
{
|
||||
add => BaseContainer.Refreshed += value;
|
||||
remove => BaseContainer.Refreshed -= value;
|
||||
}
|
||||
|
||||
public VirtualContainer(
|
||||
IContainer baseContainer,
|
||||
List<Func<IEnumerable<IContainer>, IEnumerable<IContainer>>> containerTransformators,
|
||||
List<Func<IEnumerable<IElement>, IEnumerable<IElement>>> elementTransformators,
|
||||
bool isPermanent = false,
|
||||
bool isTransitive = false,
|
||||
string? virtualContainerName = null)
|
||||
{
|
||||
BaseContainer = baseContainer;
|
||||
_containerTransformators = containerTransformators;
|
||||
_elementTransformators = elementTransformators;
|
||||
|
||||
InitItems();
|
||||
IsPermanent = isPermanent;
|
||||
IsTransitive = isTransitive;
|
||||
VirtualContainerName = virtualContainerName;
|
||||
}
|
||||
|
||||
private void InitItems()
|
||||
{
|
||||
Containers = _containerTransformators.Aggregate(BaseContainer.Containers.AsEnumerable(), (a, t) => t(a)).ToList().AsReadOnly();
|
||||
Elements = _elementTransformators.Aggregate(BaseContainer.Elements.AsEnumerable(), (a, t) => t(a)).ToList().AsReadOnly();
|
||||
|
||||
Items = Containers.Cast<IItem>().Concat(Elements).ToList().AsReadOnly();
|
||||
}
|
||||
|
||||
public IItem? GetByPath(string path) => BaseContainer.GetByPath(path);
|
||||
|
||||
public IContainer? GetParent() => BaseContainer.GetParent();
|
||||
|
||||
public void Refresh()
|
||||
{
|
||||
BaseContainer.Refresh();
|
||||
InitItems();
|
||||
}
|
||||
|
||||
public IContainer GetRealContainer() =>
|
||||
BaseContainer is VirtualContainer virtualContainer ? virtualContainer.GetRealContainer() : BaseContainer;
|
||||
|
||||
public bool HasWithName(string name) =>
|
||||
VirtualContainerName == name
|
||||
|| (BaseContainer is VirtualContainer virtualContainer
|
||||
&& virtualContainer.HasWithName(name));
|
||||
|
||||
public IContainer ExceptWithName(string name)
|
||||
{
|
||||
if (BaseContainer is VirtualContainer virtualBaseContainer && virtualBaseContainer.VirtualContainerName == name)
|
||||
{
|
||||
return new VirtualContainer(
|
||||
virtualBaseContainer.ExceptWithName(name),
|
||||
_containerTransformators,
|
||||
_elementTransformators,
|
||||
IsPermanent,
|
||||
IsTransitive,
|
||||
VirtualContainerName);
|
||||
}
|
||||
else if (VirtualContainerName == name)
|
||||
{
|
||||
return BaseContainer;
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public IContainer CloneVirtualChainFor(IContainer container, Func<VirtualContainer, bool> predicate)
|
||||
{
|
||||
var baseContainer = BaseContainer is VirtualContainer baseVirtualContainer
|
||||
? baseVirtualContainer.CloneVirtualChainFor(container, predicate)
|
||||
: container;
|
||||
|
||||
return predicate(this)
|
||||
? new VirtualContainer(
|
||||
baseContainer,
|
||||
_containerTransformators,
|
||||
_elementTransformators,
|
||||
IsPermanent,
|
||||
IsTransitive,
|
||||
VirtualContainerName)
|
||||
: baseContainer;
|
||||
}
|
||||
|
||||
public IContainer CreateContainer(string name) => BaseContainer.CreateContainer(name);
|
||||
public IElement CreateElement(string name) => BaseContainer.CreateElement(name);
|
||||
public bool IsExists(string name) => BaseContainer.IsExists(name);
|
||||
|
||||
public void Delete() => BaseContainer.Delete();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user