Add interfaces for TorrentData, Downloads, Process, ProcessFactory
Making them interfaces lets us dependency inject them, allowing a given class to be tested.
This commit is contained in:
parent
daf8a9c6da
commit
fd073b4762
8 changed files with 129 additions and 2 deletions
28
server/RdtClient.Data/Data/ITorrentData.cs
Normal file
28
server/RdtClient.Data/Data/ITorrentData.cs
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
using RdtClient.Data.Enums;
|
||||
using RdtClient.Data.Models.Data;
|
||||
|
||||
namespace RdtClient.Data.Data;
|
||||
|
||||
public interface ITorrentData
|
||||
{
|
||||
Task<IList<Torrent>> Get();
|
||||
Task<Torrent?> GetById(Guid torrentId);
|
||||
Task<Torrent?> GetByHash(String hash);
|
||||
|
||||
Task<Torrent> Add(String rdId,
|
||||
String hash,
|
||||
String? fileOrMagnetContents,
|
||||
Boolean isFile,
|
||||
DownloadClient downloadClient,
|
||||
Torrent torrent);
|
||||
|
||||
Task UpdateRdData(Torrent torrent);
|
||||
Task Update(Torrent torrent);
|
||||
Task UpdateCategory(Guid torrentId, String? category);
|
||||
Task UpdateComplete(Guid torrentId, String? error, DateTimeOffset? datetime, Boolean retry);
|
||||
Task UpdateFilesSelected(Guid torrentId, DateTimeOffset datetime);
|
||||
Task UpdatePriority(Guid torrentId, Int32? priority);
|
||||
Task UpdateRetry(Guid torrentId, DateTimeOffset? dateTime, Int32 retryCount);
|
||||
Task UpdateError(Guid torrentId, String error);
|
||||
Task Delete(Guid torrentId);
|
||||
}
|
||||
|
|
@ -4,7 +4,7 @@ using RdtClient.Data.Models.Data;
|
|||
|
||||
namespace RdtClient.Data.Data;
|
||||
|
||||
public class TorrentData(DataContext dataContext)
|
||||
public class TorrentData(DataContext dataContext) : ITorrentData
|
||||
{
|
||||
private static IList<Torrent>? _torrentCache;
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ using Download = RdtClient.Data.Models.Data.Download;
|
|||
|
||||
namespace RdtClient.Service.Services;
|
||||
|
||||
public class Downloads(DownloadData downloadData)
|
||||
public class Downloads(DownloadData downloadData) : IDownloads
|
||||
{
|
||||
public async Task<List<Download>> GetForTorrent(Guid torrentId)
|
||||
{
|
||||
|
|
|
|||
24
server/RdtClient.Service/Services/IDownloads.cs
Normal file
24
server/RdtClient.Service/Services/IDownloads.cs
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
using RdtClient.Data.Models.Data;
|
||||
|
||||
namespace RdtClient.Service.Services;
|
||||
|
||||
public interface IDownloads
|
||||
{
|
||||
Task<List<Download>> GetForTorrent(Guid torrentId);
|
||||
Task<Download?> GetById(Guid downloadId);
|
||||
Task<Download?> Get(Guid torrentId, String path);
|
||||
Task<Download> Add(Guid torrentId, String path);
|
||||
Task UpdateUnrestrictedLink(Guid downloadId, String unrestrictedLink);
|
||||
Task UpdateFileName(Guid downloadId, String fileName);
|
||||
Task UpdateDownloadStarted(Guid downloadId, DateTimeOffset? dateTime);
|
||||
Task UpdateDownloadFinished(Guid downloadId, DateTimeOffset? dateTime);
|
||||
Task UpdateUnpackingQueued(Guid downloadId, DateTimeOffset? dateTime);
|
||||
Task UpdateUnpackingStarted(Guid downloadId, DateTimeOffset? dateTime);
|
||||
Task UpdateUnpackingFinished(Guid downloadId, DateTimeOffset? dateTime);
|
||||
Task UpdateCompleted(Guid downloadId, DateTimeOffset? dateTime);
|
||||
Task UpdateError(Guid downloadId, String? error);
|
||||
Task UpdateRetryCount(Guid downloadId, Int32 retryCount);
|
||||
Task UpdateRemoteId(Guid downloadId, String remoteId);
|
||||
Task DeleteForTorrent(Guid torrentId);
|
||||
Task Reset(Guid downloadId);
|
||||
}
|
||||
16
server/RdtClient.Service/Wrappers/IProcess.cs
Normal file
16
server/RdtClient.Service/Wrappers/IProcess.cs
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
using System.Diagnostics;
|
||||
|
||||
namespace RdtClient.Service.Wrappers;
|
||||
|
||||
public interface IProcess : IDisposable
|
||||
{
|
||||
event EventHandler<String?>? OutputDataReceived;
|
||||
event EventHandler<String?>? ErrorDataReceived;
|
||||
|
||||
public ProcessStartInfo StartInfo { get; set; }
|
||||
|
||||
void BeginOutputReadLine();
|
||||
void BeginErrorReadLine();
|
||||
Boolean WaitForExit(Int32 milliseconds);
|
||||
void Start();
|
||||
}
|
||||
6
server/RdtClient.Service/Wrappers/IProcessFactory.cs
Normal file
6
server/RdtClient.Service/Wrappers/IProcessFactory.cs
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
namespace RdtClient.Service.Wrappers;
|
||||
|
||||
public interface IProcessFactory
|
||||
{
|
||||
public IProcess NewProcess();
|
||||
}
|
||||
44
server/RdtClient.Service/Wrappers/Process.cs
Normal file
44
server/RdtClient.Service/Wrappers/Process.cs
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
using System.Diagnostics;
|
||||
|
||||
namespace RdtClient.Service.Wrappers;
|
||||
|
||||
public class Process : IProcess
|
||||
{
|
||||
private readonly System.Diagnostics.Process _process = new();
|
||||
|
||||
public ProcessStartInfo StartInfo
|
||||
{
|
||||
get => _process.StartInfo;
|
||||
set => _process.StartInfo = value;
|
||||
}
|
||||
|
||||
public event EventHandler<String?>? OutputDataReceived;
|
||||
public event EventHandler<String?>? ErrorDataReceived;
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_process.Dispose();
|
||||
}
|
||||
|
||||
public void BeginOutputReadLine()
|
||||
{
|
||||
_process.OutputDataReceived += (sender, args) => OutputDataReceived?.Invoke(sender, args.Data);
|
||||
_process.BeginOutputReadLine();
|
||||
}
|
||||
|
||||
public void BeginErrorReadLine()
|
||||
{
|
||||
_process.ErrorDataReceived += (sender, args) => ErrorDataReceived?.Invoke(sender, args.Data);
|
||||
_process.BeginErrorReadLine();
|
||||
}
|
||||
|
||||
public Boolean WaitForExit(Int32 milliseconds)
|
||||
{
|
||||
return _process.WaitForExit(milliseconds);
|
||||
}
|
||||
|
||||
public void Start()
|
||||
{
|
||||
_process.Start();
|
||||
}
|
||||
}
|
||||
9
server/RdtClient.Service/Wrappers/ProcessFactory.cs
Normal file
9
server/RdtClient.Service/Wrappers/ProcessFactory.cs
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
namespace RdtClient.Service.Wrappers;
|
||||
|
||||
public class ProcessFactory: IProcessFactory
|
||||
{
|
||||
public IProcess NewProcess()
|
||||
{
|
||||
return new Process();
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue