-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from trossr32/Issue-10
Set-TransmissionAltSpeedLimits
- Loading branch information
Showing
3 changed files
with
102 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
src/PsTransmission/Session/SetTransmissionAltSpeedLimitsCmdlet.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
using System; | ||
using System.Management.Automation; | ||
using System.Threading.Tasks; | ||
using PsTransmission.Core.Services.Transmission; | ||
using Transmission.Base; | ||
using Transmission.NetCore.Client.Models; | ||
|
||
namespace Transmission.Session | ||
{ | ||
/// <summary> | ||
/// <para type="synopsis"> | ||
/// Set Transmission alt speed state. | ||
/// </para> | ||
/// <para type="description"> | ||
/// Set Transmission alt speed state. | ||
/// </para> | ||
/// <para type="description"> | ||
/// Calls the 'session-set' endpoint: https://github.com/transmission/transmission/blob/master/extras/rpc-spec.txt | ||
/// </para> | ||
/// <example> | ||
/// <para>Example 1: Enable the alt speed limit</para> | ||
/// <code>PS C:\> Set-TransmissionAltSpeedLimits -Enable</code> | ||
/// <remarks>Enable the alt speed limit.</remarks> | ||
/// </example> | ||
/// <example> | ||
/// <para>Example 2: Disable the alt speed limit</para> | ||
/// <code>PS C:\> Set-TransmissionAltSpeedLimits -Disable</code> | ||
/// <remarks>Disable the alt speed limit.</remarks> | ||
/// </example> | ||
/// <para type="link" uri="(https://github.com/trossr32/ps-transmission)">[Github]</para> | ||
/// <para type="link" uri="(https://github.com/transmission/transmission/blob/master/extras/rpc-spec.txt)">[Transmission RPC API]</para> | ||
/// </summary> | ||
[Cmdlet(VerbsCommon.Set, "TransmissionAltSpeedLimits", HelpUri = "https://github.com/trossr32/ps-transmission")] | ||
[OutputType(typeof(SessionInformation))] | ||
public class SetTransmissionAltSpeedLimitsCmdlet : BaseTransmissionCmdlet | ||
{ | ||
/// <summary> | ||
/// <para type="description"> | ||
/// Enable alt speed limits. | ||
/// </para> | ||
/// </summary> | ||
[Parameter(Mandatory = false)] | ||
public SwitchParameter Enable { get; set; } | ||
|
||
/// <summary> | ||
/// <para type="description"> | ||
/// Disable alt speed limits. | ||
/// </para> | ||
/// </summary> | ||
[Parameter(Mandatory = false)] | ||
public SwitchParameter Disable { get; set; } | ||
|
||
/// <summary> | ||
/// Implements the <see cref="BeginProcessing"/> method for <see cref="SetTransmissionAltSpeedLimitsCmdlet"/>. | ||
/// </summary> | ||
protected override void BeginProcessing() | ||
{ | ||
base.BeginProcessing(); | ||
} | ||
|
||
/// <summary> | ||
/// Implements the <see cref="ProcessRecord"/> method for <see cref="SetTransmissionAltSpeedLimitsCmdlet"/>. | ||
/// </summary> | ||
protected override void ProcessRecord() | ||
{ | ||
try | ||
{ | ||
var sessionSvc = new SessionService(); | ||
|
||
if (!Enable.IsPresent && !Disable.IsPresent) | ||
throw new Exception("Either the Enable or Disable parameter must be supplied"); | ||
|
||
var request = new SessionSettings { | ||
AlternativeSpeedEnabled = Enable.IsPresent | ||
}; | ||
|
||
bool success = Task.Run(async () => await sessionSvc.Set(request)).Result; | ||
|
||
if (success) | ||
WriteObject($"Alt speed settings {(Enable.IsPresent ? "enabled" : "disabled")} succesfully"); | ||
} | ||
catch (Exception e) | ||
{ | ||
ThrowTerminatingError(new ErrorRecord(new Exception(e.Message, e), null, ErrorCategory.OperationStopped, null)); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Implements the <see cref="EndProcessing"/> method for <see cref="SetTransmissionAltSpeedLimitsCmdlet"/>. | ||
/// Retrieve all torrents | ||
/// </summary> | ||
protected override void EndProcessing() | ||
{ | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters