Skip to content

Commit

Permalink
Merge pull request #11 from trossr32/Issue-10
Browse files Browse the repository at this point in the history
Set-TransmissionAltSpeedLimits
  • Loading branch information
trossr32 authored Sep 27, 2020
2 parents ba8b8cb + 2d70de3 commit 39c121c
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/PsTransmission/PsTransmission.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<AssemblyName>Transmission</AssemblyName>
<RootNamespace>Transmission</RootNamespace>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<AssemblyVersion>1.0.7.0</AssemblyVersion>
<Version>1.0.7</Version>
<AssemblyVersion>1.0.8.0</AssemblyVersion>
<Version>1.0.8</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
97 changes: 97 additions & 0 deletions src/PsTransmission/Session/SetTransmissionAltSpeedLimitsCmdlet.cs
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()
{

}
}
}
5 changes: 3 additions & 2 deletions src/PsTransmission/Transmission.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
RootModule = 'Transmission.dll'

# Version number of this module.
ModuleVersion = '1.0.7'
ModuleVersion = '1.0.8'

# Supported PSEditions
CompatiblePSEditions = 'Core'
Expand Down Expand Up @@ -92,7 +92,8 @@
'Set-TransmissionTorrentsLocation',
'Start-TransmissionTorrents',
'Start-TransmissionTorrentsNow',
'Stop-TransmissionTorrents'
'Stop-TransmissionTorrents',
'Set-TransmissionAltSpeedLimits'
)

# Variables to export from this module
Expand Down

0 comments on commit 39c121c

Please sign in to comment.