mirror of
https://github.com/sphildreth/roadie
synced 2024-11-29 23:50:21 +00:00
95 lines
No EOL
3 KiB
C#
95 lines
No EOL
3 KiB
C#
using Microsoft.Extensions.Logging;
|
|
using Roadie.Library.Caching;
|
|
using Roadie.Library.Configuration;
|
|
using Roadie.Library.Encoding;
|
|
using Roadie.Library.Engines;
|
|
using Roadie.Library.Factories;
|
|
using Roadie.Library.Utility;
|
|
using System;
|
|
using System.IO;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Roadie.Library.FilePlugins
|
|
{
|
|
public abstract class PluginBase : IFilePlugin
|
|
{
|
|
public abstract string[] HandlesTypes { get; }
|
|
|
|
public int MinWeightToDelete => Configuration.FilePlugins.MinWeightToDelete;
|
|
|
|
protected IArtistFactory ArtistFactory { get; }
|
|
|
|
protected IArtistLookupEngine ArtistLookupEngine { get; }
|
|
|
|
protected ICacheManager CacheManager { get; }
|
|
|
|
protected IRoadieSettings Configuration { get; }
|
|
|
|
protected IHttpEncoder HttpEncoder { get; }
|
|
|
|
protected IImageFactory ImageFactory { get; }
|
|
|
|
protected ILogger Logger { get; }
|
|
|
|
protected IReleaseFactory ReleaseFactory { get; }
|
|
|
|
protected IReleaseLookupEngine ReleaseLookupEngine { get; }
|
|
|
|
public PluginBase(IRoadieSettings configuration, IHttpEncoder httpEncoder, IArtistFactory artistFactory,
|
|
IReleaseFactory releaseFactory, IImageFactory imageFactory, ICacheManager cacheManager, ILogger logger,
|
|
IArtistLookupEngine artistLookupEngine, IReleaseLookupEngine releaseLookupEngine)
|
|
{
|
|
Configuration = configuration;
|
|
HttpEncoder = httpEncoder;
|
|
ArtistFactory = artistFactory;
|
|
ReleaseFactory = releaseFactory;
|
|
ImageFactory = imageFactory;
|
|
CacheManager = cacheManager;
|
|
Logger = logger;
|
|
ArtistLookupEngine = artistLookupEngine;
|
|
ReleaseLookupEngine = releaseLookupEngine;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Check if exists if not make given folder
|
|
/// </summary>
|
|
/// <param name="folder">Folder To Check</param>
|
|
/// <returns>False if Exists, True if Made</returns>
|
|
public static bool CheckMakeFolder(string folder)
|
|
{
|
|
SimpleContract.Requires<ArgumentException>(!string.IsNullOrEmpty(folder), "Invalid Folder");
|
|
|
|
if (!Directory.Exists(folder))
|
|
{
|
|
Directory.CreateDirectory(folder);
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public abstract Task<OperationResult<bool>> Process(string destinationRoot, FileInfo fileInfo, bool doJustInfo,
|
|
int? submissionId);
|
|
|
|
protected virtual bool IsFileLocked(FileInfo file)
|
|
{
|
|
FileStream stream = null;
|
|
|
|
try
|
|
{
|
|
stream = file.Open(FileMode.Open, FileAccess.ReadWrite, FileShare.None);
|
|
}
|
|
catch (IOException)
|
|
{
|
|
return true;
|
|
}
|
|
finally
|
|
{
|
|
if (stream != null) stream.Close();
|
|
}
|
|
|
|
//file is not locked
|
|
return false;
|
|
}
|
|
}
|
|
} |