From b3d86d278bc5843bc8277fec5b06136a967583e4 Mon Sep 17 00:00:00 2001 From: Rob Green Date: Fri, 14 Jan 2022 17:14:21 +0000 Subject: [PATCH] Fixes 13 Change CorruptEver property from int to long Update nuget packages and make associated changes --- .../PsTransmission.Core.csproj | 6 +- .../Services/EncryptionService.cs | 8 +-- .../Services/Transmission/SessionService.cs | 20 ++---- .../Services/Transmission/SystemService.cs | 10 +-- .../Services/Transmission/TorrentService.cs | 62 ++++++------------- .../Base/BaseTransmissionCmdlet.cs | 15 ++++- src/PsTransmission/PsTransmission.csproj | 4 +- src/PsTransmission/Transmission.psd1 | 2 +- .../Models/Torrent.cs | 8 +-- .../Transmission.NetCore.Client.csproj | 4 +- 10 files changed, 55 insertions(+), 84 deletions(-) diff --git a/src/PsTransmission.Core/PsTransmission.Core.csproj b/src/PsTransmission.Core/PsTransmission.Core.csproj index be2896a..795916f 100644 --- a/src/PsTransmission.Core/PsTransmission.Core.csproj +++ b/src/PsTransmission.Core/PsTransmission.Core.csproj @@ -5,7 +5,11 @@ - + + + + + diff --git a/src/PsTransmission.Core/Services/EncryptionService.cs b/src/PsTransmission.Core/Services/EncryptionService.cs index 0766406..056b9a7 100644 --- a/src/PsTransmission.Core/Services/EncryptionService.cs +++ b/src/PsTransmission.Core/Services/EncryptionService.cs @@ -65,12 +65,10 @@ public static async Task Decrypt(string cipherText) /// Build an encryption key unique to the host machine /// /// - private static string EncryptionKey() - { - return new DeviceIdBuilder() - .AddProcessorId() + private static string EncryptionKey() => + new DeviceIdBuilder() + .OnWindows(windows => windows.AddProcessorId()) .AddMachineName() .ToString(); - } } } diff --git a/src/PsTransmission.Core/Services/Transmission/SessionService.cs b/src/PsTransmission.Core/Services/Transmission/SessionService.cs index 4d19ac1..2984fec 100644 --- a/src/PsTransmission.Core/Services/Transmission/SessionService.cs +++ b/src/PsTransmission.Core/Services/Transmission/SessionService.cs @@ -18,37 +18,25 @@ public SessionService() /// Get session information /// /// - public async Task Get() - { - return await _client.SessionGetAsync(); - } + public async Task Get() => await _client.SessionGetAsync(); /// /// Get session statistics /// /// - public async Task GetStats() - { - return await _client.SessionGetStatisticAsync(); - } + public async Task GetStats() => await _client.SessionGetStatisticAsync(); /// /// Set session settings /// /// - public async Task Set(SessionSettings request) - { - return await _client.SessionSetAsync(request); - } + public async Task Set(SessionSettings request) => await _client.SessionSetAsync(request); /// /// Close session
/// Careful with this one; it essentially shuts transmission down and will need to be restarted to bring it back. ///
/// - public async Task Close() - { - return await _client.SessionCloseAsync(); - } + public async Task Close() => await _client.SessionCloseAsync(); } } diff --git a/src/PsTransmission.Core/Services/Transmission/SystemService.cs b/src/PsTransmission.Core/Services/Transmission/SystemService.cs index 6696718..8ba728a 100644 --- a/src/PsTransmission.Core/Services/Transmission/SystemService.cs +++ b/src/PsTransmission.Core/Services/Transmission/SystemService.cs @@ -17,18 +17,12 @@ public SystemService() /// Port test /// /// - public async Task TestPort() - { - return await _client.PortTestAsync(); - } + public async Task TestPort() => await _client.PortTestAsync(); /// /// Update blocklists /// /// success flag and error message, if applicable - public async Task<(bool success, string error)> UpdateBlockList() - { - return await _client.UpdateBlockListAsync(); - } + public async Task<(bool success, string error)> UpdateBlockList() => await _client.UpdateBlockListAsync(); } } diff --git a/src/PsTransmission.Core/Services/Transmission/TorrentService.cs b/src/PsTransmission.Core/Services/Transmission/TorrentService.cs index c924664..624ced6 100644 --- a/src/PsTransmission.Core/Services/Transmission/TorrentService.cs +++ b/src/PsTransmission.Core/Services/Transmission/TorrentService.cs @@ -22,36 +22,28 @@ public TorrentService() /// Retrieve all torrents. /// /// - public async Task GetTorrents(List torrentIds = null) - { - string[] includeFields; - - return torrentIds != null + public async Task GetTorrents(List torrentIds = null) => + torrentIds != null ? (await _client.TorrentGetAsync(TorrentFields.AllFields, torrentIds.ToArray()))?.TorrentList : (await _client.TorrentGetAsync(TorrentFields.AllFields))?.TorrentList; - } /// /// Get completed torrents. /// /// - public async Task GetCompletedTorrents() - { - return (await GetTorrents()) + public async Task GetCompletedTorrents() => + (await GetTorrents()) .Where(t => t.PercentDone == 1.0) .ToArray(); - } /// /// Get incomplete torrents. /// /// - public async Task GetIncompleteTorrents() - { - return (await GetTorrents()) + public async Task GetIncompleteTorrents() => + (await GetTorrents()) .Where(t => t.PercentDone < 1.0) .ToArray(); - } /// /// Stop torrents. If the supplied list of ids is null, all torrents will be stopped. @@ -244,9 +236,8 @@ public async Task GetIncompleteTorrents() /// Move torrents in queue. /// /// - public async Task MoveTorrents(MoveInQueue moveInQueue, List torrentIds) - { - return moveInQueue switch + public async Task MoveTorrents(MoveInQueue moveInQueue, List torrentIds) => + moveInQueue switch { MoveInQueue.Up => await _client.TorrentQueueMoveUpAsync(torrentIds.ToArray()), MoveInQueue.Down => await _client.TorrentQueueMoveDownAsync(torrentIds.ToArray()), @@ -254,16 +245,13 @@ public async Task MoveTorrents(MoveInQueue moveInQueue, List torrentI MoveInQueue.Bottom => await _client.TorrentQueueMoveBottomAsync(torrentIds.ToArray()), _ => throw new ArgumentOutOfRangeException(nameof(moveInQueue), moveInQueue, null) }; - } /// /// Verify torrents. /// /// - public async Task VerifyTorrents(List torrentIds) - { - return await _client.TorrentVerifyAsync(torrentIds.ToArray()); - } + public async Task VerifyTorrents(List torrentIds) => + await _client.TorrentVerifyAsync(torrentIds.ToArray()); /// /// Re-announce torrents
@@ -271,10 +259,8 @@ public async Task VerifyTorrents(List torrentIds) ///
/// /// - public async Task ReannounceTorrents(List torrentIds) - { - return await _client.TorrentReannounceAsync(torrentIds.ToArray()); - } + public async Task ReannounceTorrents(List torrentIds) => + await _client.TorrentReannounceAsync(torrentIds.ToArray()); /// /// Rename a file or directory in a torrent @@ -282,10 +268,8 @@ public async Task ReannounceTorrents(List torrentIds) /// The torrent whose path will be renamed /// The path to the file or folder that will be renamed /// The file or folder's new name - public async Task RenameTorrentPath(int torrentId, string path, string name) - { - return await _client.TorrentRenamePathAsync(torrentId, path, name); - } + public async Task RenameTorrentPath(int torrentId, string path, string name) => + await _client.TorrentRenamePathAsync(torrentId, path, name); /// /// Set new location for torrents files (API: torrent-set-location) @@ -293,29 +277,23 @@ public async Task RenameTorrentPath(int torrentId, string path, /// Torrent ids /// The new torrent location /// Move from previous location - public async Task SetTorrentsLocation(List torrentIds, string location, bool move) - { - return await _client.TorrentSetLocationAsync(torrentIds.ToArray(), location, move); - } + public async Task SetTorrentsLocation(List torrentIds, string location, bool move) => + await _client.TorrentSetLocationAsync(torrentIds.ToArray(), location, move); /// /// Set torrent params /// /// /// - public async Task SetTorrents(TorrentSettings request) - { - return await _client.TorrentSetAsync(request); - } + public async Task SetTorrents(TorrentSettings request) => + await _client.TorrentSetAsync(request); /// /// Add multiple torrents /// /// /// A list of successful and failed results - public async Task AddTorrents(List requests) - { - return await _client.TorrentsAddAsync(requests); - } + public async Task AddTorrents(List requests) => + await _client.TorrentsAddAsync(requests); } } diff --git a/src/PsTransmission/Base/BaseTransmissionCmdlet.cs b/src/PsTransmission/Base/BaseTransmissionCmdlet.cs index 432977c..19f3d59 100644 --- a/src/PsTransmission/Base/BaseTransmissionCmdlet.cs +++ b/src/PsTransmission/Base/BaseTransmissionCmdlet.cs @@ -17,7 +17,20 @@ protected override void BeginProcessing() if (TransmissionContext.HasCredentials) return; - TransmissionContext.Credentials = Task.Run(async () => await AuthService.GetConfig()).Result; + try + { + TransmissionContext.Credentials = Task.Run(async () => await AuthService.GetConfig()).Result; + } + catch (Exception e) + { + var credsGetError = "Failed to retrieve credentials. If you have upgraded from v1.0.8 or lower then this is likely caused by the device id package dependency that is used to encrypt your credentials being upgraded. Please remove your existing credentials with Remove-TransmissionCredentials and then set them again with Set-TransmissionCredentials."; + + ThrowTerminatingError(new ErrorRecord(new Exception(credsGetError, e), null, ErrorCategory.AuthenticationError, null) + { + CategoryInfo = { Reason = credsGetError }, + ErrorDetails = new ErrorDetails(credsGetError) + }); + } if (TransmissionContext.HasCredentials) return; diff --git a/src/PsTransmission/PsTransmission.csproj b/src/PsTransmission/PsTransmission.csproj index 7722e21..f0f62e8 100644 --- a/src/PsTransmission/PsTransmission.csproj +++ b/src/PsTransmission/PsTransmission.csproj @@ -5,8 +5,8 @@ Transmission Transmission true - 1.0.8.0 - 1.0.8 + 1.0.9.0 + 1.0.9 diff --git a/src/PsTransmission/Transmission.psd1 b/src/PsTransmission/Transmission.psd1 index 93cc2b1..dbfa492 100644 --- a/src/PsTransmission/Transmission.psd1 +++ b/src/PsTransmission/Transmission.psd1 @@ -12,7 +12,7 @@ RootModule = 'Transmission.dll' # Version number of this module. - ModuleVersion = '1.0.8' + ModuleVersion = '1.0.9' # Supported PSEditions CompatiblePSEditions = 'Core' diff --git a/src/Transmission.NetCore.Client/Models/Torrent.cs b/src/Transmission.NetCore.Client/Models/Torrent.cs index 22115ef..0c0f530 100644 --- a/src/Transmission.NetCore.Client/Models/Torrent.cs +++ b/src/Transmission.NetCore.Client/Models/Torrent.cs @@ -63,11 +63,7 @@ public class Torrent [JsonProperty("uploadedEver")] public long UploadedEver { get; set; } - - - - - + [JsonProperty("activityDate")] public int ActivityDate { get; set; } @@ -78,7 +74,7 @@ public class Torrent public string Comment { get; set; } [JsonProperty("corruptEver")] - public int CorruptEver { get; set; } + public long CorruptEver { get; set; } [JsonProperty("creator")] public string Creator { get; set; } diff --git a/src/Transmission.NetCore.Client/Transmission.NetCore.Client.csproj b/src/Transmission.NetCore.Client/Transmission.NetCore.Client.csproj index 3a0d954..fdb7af6 100644 --- a/src/Transmission.NetCore.Client/Transmission.NetCore.Client.csproj +++ b/src/Transmission.NetCore.Client/Transmission.NetCore.Client.csproj @@ -5,8 +5,8 @@ - - + +