ContentProvider more async
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
using FileTime.Core.ContentAccess;
|
||||
using FileTime.Core.Models;
|
||||
|
||||
namespace FileTime.Providers.Local;
|
||||
|
||||
public interface ILocalContentProvider : IContentProvider
|
||||
{
|
||||
|
||||
NativePath GetNativePath(FullName fullName);
|
||||
}
|
||||
@@ -54,12 +54,13 @@ public sealed partial class LocalContentProvider : ContentProviderBase, ILocalCo
|
||||
});*/
|
||||
}
|
||||
|
||||
public override bool CanHandlePath(NativePath path)
|
||||
public override async Task<bool> CanHandlePathAsync(NativePath path)
|
||||
{
|
||||
var rootDrive = Items
|
||||
.FirstOrDefault(r =>
|
||||
var rootDrive = await Items
|
||||
.ToAsyncEnumerable()
|
||||
.FirstOrDefaultAwaitAsync(async r =>
|
||||
path.Path.StartsWith(
|
||||
GetNativePath(r.Path).Path,
|
||||
(await GetNativePathAsync(r.Path)).Path,
|
||||
_isCaseInsensitive
|
||||
? StringComparison.InvariantCultureIgnoreCase
|
||||
: StringComparison.InvariantCulture
|
||||
@@ -73,8 +74,8 @@ public sealed partial class LocalContentProvider : ContentProviderBase, ILocalCo
|
||||
{
|
||||
var rootDriveInfos = _rootDriveInfos.Value;
|
||||
var rootDriveInfo = rootDriveInfos.FirstOrDefault(d => path.Path.StartsWith(d.Path.Path));
|
||||
|
||||
if(rootDriveInfo is null) return null;
|
||||
|
||||
if (rootDriveInfo is null) return null;
|
||||
|
||||
return new VolumeSizeInfo(rootDriveInfo.Size, rootDriveInfo.Free);
|
||||
}
|
||||
@@ -391,7 +392,10 @@ public sealed partial class LocalContentProvider : ContentProviderBase, ILocalCo
|
||||
nativePath.TrimStart(Constants.SeparatorChar).Split(Path.DirectorySeparatorChar)))
|
||||
.TrimEnd(Constants.SeparatorChar))!;
|
||||
|
||||
public override NativePath GetNativePath(FullName fullName)
|
||||
public override ValueTask<NativePath> GetNativePathAsync(FullName fullName)
|
||||
=> ValueTask.FromResult(GetNativePath(fullName));
|
||||
|
||||
public NativePath GetNativePath(FullName fullName)
|
||||
{
|
||||
var path = string.Join(Path.DirectorySeparatorChar, fullName.Path.Split(Constants.SeparatorChar).Skip(1));
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && !path.StartsWith("/")) path = "/" + path;
|
||||
|
||||
@@ -24,7 +24,7 @@ public class LocalItemCreator : ItemCreatorBase<ILocalContentProvider>
|
||||
public override async Task CreateContainerAsync(ILocalContentProvider contentProvider, FullName fullName)
|
||||
{
|
||||
_logger.LogTrace("Start creating container {FullName}", fullName);
|
||||
var path = contentProvider.GetNativePath(fullName).Path;
|
||||
var path = (await contentProvider.GetNativePathAsync(fullName)).Path;
|
||||
if (Directory.Exists(path))
|
||||
{
|
||||
_logger.LogTrace("Container with path {Path} already exists", path);
|
||||
@@ -54,7 +54,7 @@ public class LocalItemCreator : ItemCreatorBase<ILocalContentProvider>
|
||||
public override async Task CreateElementAsync(ILocalContentProvider contentProvider, FullName fullName)
|
||||
{
|
||||
_logger.LogTrace("Start creating element {FullName}", fullName);
|
||||
var path = contentProvider.GetNativePath(fullName).Path;
|
||||
var path = (await contentProvider.GetNativePathAsync(fullName)).Path;
|
||||
if (File.Exists(path))
|
||||
{
|
||||
_logger.LogTrace("Element with path {Path} already exists", path);
|
||||
|
||||
@@ -24,7 +24,7 @@ public class LocalItemDeleter : IItemDeleter<ILocalContentProvider>
|
||||
public async Task DeleteAsync(ILocalContentProvider contentProvider, FullName fullName)
|
||||
{
|
||||
_logger.LogTrace("Start deleting item {FullName}", fullName);
|
||||
var nativePath = contentProvider.GetNativePath(fullName).Path;
|
||||
var nativePath = (await contentProvider.GetNativePathAsync(fullName)).Path;
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
@@ -26,8 +26,8 @@ public class LocalItemMover : IItemMover<ILocalContentProvider>
|
||||
_logger.LogTrace("Start renaming item {FullName}", fullName);
|
||||
try
|
||||
{
|
||||
var source = contentProvider.GetNativePath(fullName);
|
||||
var destination = contentProvider.GetNativePath(newPath);
|
||||
var source = await contentProvider.GetNativePathAsync(fullName);
|
||||
var destination = await contentProvider.GetNativePathAsync(newPath);
|
||||
|
||||
if (File.Exists(source.Path))
|
||||
{
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using System.Diagnostics;
|
||||
using FileTime.Core.Models;
|
||||
using FileTime.Providers.Remote;
|
||||
using FileTime.Server.Common;
|
||||
using InitableService;
|
||||
|
||||
namespace FileTime.Providers.LocalAdmin;
|
||||
|
||||
@@ -21,18 +21,51 @@ public sealed class RemoteContentProvider : ContentProviderBase, IRemoteContentP
|
||||
RemoteProviderName = remoteName;
|
||||
_remoteConnectionProvider = remoteConnectionProvider;
|
||||
}
|
||||
public async Task<IRemoteConnection> GetRemoteConnectionAsync()
|
||||
|
||||
public async Task<IRemoteConnection> GetRemoteConnectionAsync()
|
||||
=> await _remoteConnectionProvider();
|
||||
|
||||
//TODO implement
|
||||
public override Task<IItem> GetItemByNativePathAsync(NativePath nativePath, PointInTime pointInTime, bool forceResolve = false, AbsolutePathType forceResolvePathType = AbsolutePathType.Unknown, ItemInitializationSettings itemInitializationSettings = default) => throw new NotImplementedException();
|
||||
public override Task<IItem> GetItemByNativePathAsync(
|
||||
NativePath nativePath,
|
||||
PointInTime pointInTime,
|
||||
bool forceResolve = false,
|
||||
AbsolutePathType forceResolvePathType = AbsolutePathType.Unknown,
|
||||
ItemInitializationSettings itemInitializationSettings = default) =>
|
||||
throw new NotImplementedException();
|
||||
|
||||
public override NativePath GetNativePath(FullName fullName) => throw new NotImplementedException();
|
||||
//TODO: make it async
|
||||
public override async ValueTask<NativePath> GetNativePathAsync(FullName fullName)
|
||||
{
|
||||
var remoteFullname = new FullName(ConvertLocalFullNameToRemote(fullName));
|
||||
|
||||
var connection = await GetRemoteConnectionAsync();
|
||||
var remoteNativePath = await connection.GetNativePathAsync(remoteFullname);
|
||||
return new NativePath(remoteNativePath!.Path);
|
||||
}
|
||||
|
||||
public override FullName GetFullName(NativePath nativePath) => throw new NotImplementedException();
|
||||
|
||||
public override Task<byte[]?> GetContentAsync(IElement element, int? maxLength = null, CancellationToken cancellationToken = default) => throw new NotImplementedException();
|
||||
|
||||
public override bool CanHandlePath(NativePath path) => throw new NotImplementedException();
|
||||
public override Task<bool> CanHandlePathAsync(NativePath path) => throw new NotImplementedException();
|
||||
public override VolumeSizeInfo? GetVolumeSizeInfo(FullName path) => throw new NotImplementedException();
|
||||
|
||||
private string ConvertLocalFullNameToRemote(FullName fullName)
|
||||
{
|
||||
var remotePath =
|
||||
RemoteProviderName
|
||||
+ Constants.SeparatorChar
|
||||
+ fullName.Path[Name.Length..];
|
||||
return remotePath;
|
||||
}
|
||||
|
||||
private FullName ConvertRemoteFullnameToLocal(string remotePath)
|
||||
{
|
||||
var localPath =
|
||||
Name
|
||||
+ Constants.SeparatorChar
|
||||
+ remotePath[RemoteProviderName.Length..];
|
||||
return new FullName(localPath);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
using FileTime.Core.ContentAccess;
|
||||
using FileTime.Core.Models;
|
||||
using FileTime.Server.Common;
|
||||
using InitableService;
|
||||
|
||||
namespace FileTime.Providers.Remote;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using FileTime.Core.ContentAccess;
|
||||
using FileTime.Core.Models;
|
||||
using FileTime.Server.Common;
|
||||
using InitableService;
|
||||
|
||||
namespace FileTime.Providers.Remote;
|
||||
|
||||
Reference in New Issue
Block a user