IVirtualDiskProvider abstraction, need a lot of work on the class names.

This commit is contained in:
Taloth Saldono 2017-11-07 17:39:16 +01:00
parent 2a0a4cfb6d
commit 74fbc97835
10 changed files with 186 additions and 30 deletions

View File

@ -946,10 +946,14 @@
<Compile Include="ProgressMessaging\ProgressMessageContext.cs" /> <Compile Include="ProgressMessaging\ProgressMessageContext.cs" />
<Compile Include="Qualities\QualitySource.cs" /> <Compile Include="Qualities\QualitySource.cs" />
<Compile Include="Qualities\Revision.cs" /> <Compile Include="Qualities\Revision.cs" />
<Compile Include="TransferProviders\CustomTransferProvider.cs" /> <Compile Include="TransferProviders\Providers\DefaultTransfer.cs" />
<Compile Include="TransferProviders\Providers\Dummy.cs" />
<Compile Include="TransferProviders\TransferProviderDefinition.cs" />
<Compile Include="TransferProviders\TransferProviderRepository.cs" />
<Compile Include="TransferProviders\Providers\CustomTransfer.cs" />
<Compile Include="TransferProviders\ITransferProvider.cs" /> <Compile Include="TransferProviders\ITransferProvider.cs" />
<Compile Include="TransferProviders\IVirtualDiskProvider.cs" /> <Compile Include="TransferProviders\IVirtualDiskProvider.cs" />
<Compile Include="TransferProviders\MountTransferProvider.cs" /> <Compile Include="TransferProviders\Providers\MountTransfer.cs" />
<Compile Include="TransferProviders\old\RemotePathMapping.cs" /> <Compile Include="TransferProviders\old\RemotePathMapping.cs" />
<Compile Include="TransferProviders\old\RemotePathMappingRepository.cs" /> <Compile Include="TransferProviders\old\RemotePathMappingRepository.cs" />
<Compile Include="TransferProviders\old\RemotePathMappingService.cs" /> <Compile Include="TransferProviders\old\RemotePathMappingService.cs" />
@ -1126,7 +1130,10 @@
<Compile Include="ThingiProvider\Status\ProviderStatusRepository.cs" /> <Compile Include="ThingiProvider\Status\ProviderStatusRepository.cs" />
<Compile Include="ThingiProvider\Status\ProviderStatusServiceBase.cs" /> <Compile Include="ThingiProvider\Status\ProviderStatusServiceBase.cs" />
<Compile Include="TinyTwitter.cs" /> <Compile Include="TinyTwitter.cs" />
<Compile Include="TransferProviders\TransferProviderBase.cs" />
<Compile Include="TransferProviders\TransferProviderFactory.cs" /> <Compile Include="TransferProviders\TransferProviderFactory.cs" />
<Compile Include="TransferProviders\TransferProviderService.cs" />
<Compile Include="TransferProviders\TransferTask.cs" />
<Compile Include="Tv\Actor.cs" /> <Compile Include="Tv\Actor.cs" />
<Compile Include="Tv\AddSeriesOptions.cs" /> <Compile Include="Tv\AddSeriesOptions.cs" />
<Compile Include="Tv\AddSeriesService.cs" /> <Compile Include="Tv\AddSeriesService.cs" />

View File

@ -5,10 +5,16 @@ using NzbDrone.Core.ThingiProvider;
namespace NzbDrone.Core.TransferProviders namespace NzbDrone.Core.TransferProviders
{ {
public interface ITransferProvider : IProvider, IVirtualDiskProvider public interface ITransferProvider : IProvider
{ {
// TODO: Perhaps change 'string' to 'DownloadClientPath' struct/class so we're more typesafe.
// Whether the TransferProvider is ready to be accessed. (Useful for external transfers that may not have finished yet) // Whether the TransferProvider is ready to be accessed. (Useful for external transfers that may not have finished yet)
bool IsAvailable(string downloadClientPath); bool IsAvailable(string downloadClientPath);
bool IsAvailable(DownloadClientItem item); bool IsAvailable(DownloadClientItem item);
// Returns a wrapper for the specific download. Optionally we might want to supply a 'tempDir' that's close to the series path, in case the TransferProvider needs an intermediate location.
IVirtualDiskProvider GetFileSystemWrapper(string downloadClientPath);
IVirtualDiskProvider GetFileSystemWrapper(DownloadClientItem item);
} }
} }

View File

@ -10,7 +10,16 @@ namespace NzbDrone.Core.TransferProviders
// Any Move/Copy action should return an asynchroneous context representing the transfer in progress. So it can be shown in CDH / Activity->Queue. // Any Move/Copy action should return an asynchroneous context representing the transfer in progress. So it can be shown in CDH / Activity->Queue.
public interface IVirtualDiskProvider // : IDiskProvider public interface IVirtualDiskProvider // : IDiskProvider
{ {
// Whether the VirtualFileSystem supports direct streaming of the file content.
bool SupportStreaming { get; }
// Returns recursive list of all files in the 'volume'/'filesystem'/'dataset' (whatever we want to call it).
string[] GetFiles();
// Copies file from the virtual filesystem to the actual one. // Copies file from the virtual filesystem to the actual one.
TransferTask CopyFile(string vfsSourcePath, string destinationPath); TransferTask CopyFile(string vfsSourcePath, string destinationPath);
// Move file from the virtual filesystem to the actual one.
TransferTask MoveFile(string vfsSourcePath, string destinationPath);
} }
} }

View File

@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.Linq;
using FluentValidation.Results;
using NzbDrone.Core.ThingiProvider;
namespace NzbDrone.Core.TransferProviders.Providers
{
// Represents a local filesystem transfer.
class DefaultTransfer : TransferProviderBase<NullConfig>
{
public override IEnumerable<ProviderDefinition> DefaultDefinitions
{
get
{
yield return new TransferProviderDefinition
{
Enable = true,
Name = "Default",
ImplementationName = nameof(DefaultTransfer),
Implementation = nameof(DefaultTransfer),
Settings = NullConfig.Instance
};
}
}
public override string Link
{
get { throw new NotImplementedException(); }
}
public override string Name
{
get { throw new NotImplementedException(); }
}
public override ValidationResult Test()
{
throw new NotImplementedException();
}
}
}

View File

@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FluentValidation.Results;
using NzbDrone.Core.ThingiProvider;
namespace NzbDrone.Core.TransferProviders.Providers
{
// Marks the files are permanently unavailable. Perhaps useful in fire-and-forget.
class Dummy : TransferProviderBase<NullConfig>
{
public override string Link
{
get { throw new NotImplementedException(); }
}
public override string Name
{
get { throw new NotImplementedException(); }
}
public override ValidationResult Test()
{
throw new NotImplementedException();
}
}
}

View File

@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using FluentValidation.Results;
using NzbDrone.Core.ThingiProvider;
namespace NzbDrone.Core.TransferProviders
{
public abstract class TransferProviderBase<TSettings> : ITransferProvider where TSettings : IProviderConfig, new()
{
public abstract string Name { get; }
public Type ConfigContract => typeof(TSettings);
public virtual ProviderMessage Message => null;
public virtual IEnumerable<ProviderDefinition> DefaultDefinitions => new List<ProviderDefinition>();
public ProviderDefinition Definition { get; set; }
public abstract ValidationResult Test();
public abstract string Link { get; }
public virtual object RequestAction(string action, IDictionary<string, string> query) { return null; }
}
}

View File

@ -0,0 +1,14 @@
using System;
using System.Linq;
using NzbDrone.Core.ThingiProvider;
namespace NzbDrone.Core.TransferProviders
{
public class TransferProviderDefinition : ProviderDefinition
{
public int DownloadClientId { get; set; }
// OR
// Path could be extracted from download client.
//public string DownloadClientRootPath { get; set; }
}
}

View File

@ -11,36 +11,10 @@ using NzbDrone.Core.Validation;
namespace NzbDrone.Core.TransferProviders namespace NzbDrone.Core.TransferProviders
{ {
public class TransferProviderDefinition : ProviderDefinition
{
}
public interface ITransferProviderFactory : IProviderFactory<ITransferProvider, TransferProviderDefinition> public interface ITransferProviderFactory : IProviderFactory<ITransferProvider, TransferProviderDefinition>
{ {
} }
public abstract class TransferProviderBase<TSettings> : ITransferProvider where TSettings : IProviderConfig, new()
{
public abstract string Name { get; }
public Type ConfigContract => typeof(TSettings);
public virtual ProviderMessage Message => null;
public IEnumerable<ProviderDefinition> DefaultDefinitions => new List<ProviderDefinition>();
public ProviderDefinition Definition { get; set; }
public abstract ValidationResult Test();
public abstract string Link { get; }
public virtual object RequestAction(string action, IDictionary<string, string> query) { return null; }
}
public interface ITransferProviderRepository : IProviderRepository<TransferProviderDefinition>
{
}
public class TransferProviderFactory : ProviderFactory<ITransferProvider, TransferProviderDefinition>, ITransferProviderFactory public class TransferProviderFactory : ProviderFactory<ITransferProvider, TransferProviderDefinition>, ITransferProviderFactory
{ {
public TransferProviderFactory(ITransferProviderRepository providerRepository, IEnumerable<ITransferProvider> providers, IContainer container, IEventAggregator eventAggregator, Logger logger) public TransferProviderFactory(ITransferProviderRepository providerRepository, IEnumerable<ITransferProvider> providers, IContainer container, IEventAggregator eventAggregator, Logger logger)

View File

@ -0,0 +1,11 @@
using System;
using System.Linq;
using NzbDrone.Core.ThingiProvider;
namespace NzbDrone.Core.TransferProviders
{
public interface ITransferProviderRepository : IProviderRepository<TransferProviderDefinition>
{
}
}

View File

@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NLog;
using NzbDrone.Core.Download;
using NzbDrone.Core.ThingiProvider;
using NzbDrone.Core.TransferProviders.Providers;
namespace NzbDrone.Core.TransferProviders
{
public interface ITransferProviderService
{
ITransferProvider GetProvider(int downloadClientId);
}
public class TransferProviderService : ITransferProviderService
{
private readonly ITransferProviderFactory _transferProviderFactory;
private readonly Logger _logger;
public TransferProviderService(ITransferProviderFactory transferProviderFactory, Logger logger)
{
_transferProviderFactory = transferProviderFactory;
_logger = logger;
}
public ITransferProvider GetProvider(int downloadClientId)
{
var definition = _transferProviderFactory.All().FirstOrDefault(v => v.DownloadClientId == downloadClientId);
if (definition == null)
{
definition = _transferProviderFactory.GetDefaultDefinitions().First(v => v.ImplementationName == nameof(DefaultTransfer));
}
return _transferProviderFactory.GetInstance(definition);
}
}
}