Skip to content

Commit 39c121c

Browse files
authored
Merge pull request #11 from trossr32/Issue-10
Set-TransmissionAltSpeedLimits
2 parents ba8b8cb + 2d70de3 commit 39c121c

File tree

3 files changed

+102
-4
lines changed

3 files changed

+102
-4
lines changed

src/PsTransmission/PsTransmission.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
<AssemblyName>Transmission</AssemblyName>
66
<RootNamespace>Transmission</RootNamespace>
77
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
8-
<AssemblyVersion>1.0.7.0</AssemblyVersion>
9-
<Version>1.0.7</Version>
8+
<AssemblyVersion>1.0.8.0</AssemblyVersion>
9+
<Version>1.0.8</Version>
1010
</PropertyGroup>
1111

1212
<ItemGroup>
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
using System;
2+
using System.Management.Automation;
3+
using System.Threading.Tasks;
4+
using PsTransmission.Core.Services.Transmission;
5+
using Transmission.Base;
6+
using Transmission.NetCore.Client.Models;
7+
8+
namespace Transmission.Session
9+
{
10+
/// <summary>
11+
/// <para type="synopsis">
12+
/// Set Transmission alt speed state.
13+
/// </para>
14+
/// <para type="description">
15+
/// Set Transmission alt speed state.
16+
/// </para>
17+
/// <para type="description">
18+
/// Calls the 'session-set' endpoint: https://github.com/transmission/transmission/blob/master/extras/rpc-spec.txt
19+
/// </para>
20+
/// <example>
21+
/// <para>Example 1: Enable the alt speed limit</para>
22+
/// <code>PS C:\> Set-TransmissionAltSpeedLimits -Enable</code>
23+
/// <remarks>Enable the alt speed limit.</remarks>
24+
/// </example>
25+
/// <example>
26+
/// <para>Example 2: Disable the alt speed limit</para>
27+
/// <code>PS C:\> Set-TransmissionAltSpeedLimits -Disable</code>
28+
/// <remarks>Disable the alt speed limit.</remarks>
29+
/// </example>
30+
/// <para type="link" uri="(https://github.com/trossr32/ps-transmission)">[Github]</para>
31+
/// <para type="link" uri="(https://github.com/transmission/transmission/blob/master/extras/rpc-spec.txt)">[Transmission RPC API]</para>
32+
/// </summary>
33+
[Cmdlet(VerbsCommon.Set, "TransmissionAltSpeedLimits", HelpUri = "https://github.com/trossr32/ps-transmission")]
34+
[OutputType(typeof(SessionInformation))]
35+
public class SetTransmissionAltSpeedLimitsCmdlet : BaseTransmissionCmdlet
36+
{
37+
/// <summary>
38+
/// <para type="description">
39+
/// Enable alt speed limits.
40+
/// </para>
41+
/// </summary>
42+
[Parameter(Mandatory = false)]
43+
public SwitchParameter Enable { get; set; }
44+
45+
/// <summary>
46+
/// <para type="description">
47+
/// Disable alt speed limits.
48+
/// </para>
49+
/// </summary>
50+
[Parameter(Mandatory = false)]
51+
public SwitchParameter Disable { get; set; }
52+
53+
/// <summary>
54+
/// Implements the <see cref="BeginProcessing"/> method for <see cref="SetTransmissionAltSpeedLimitsCmdlet"/>.
55+
/// </summary>
56+
protected override void BeginProcessing()
57+
{
58+
base.BeginProcessing();
59+
}
60+
61+
/// <summary>
62+
/// Implements the <see cref="ProcessRecord"/> method for <see cref="SetTransmissionAltSpeedLimitsCmdlet"/>.
63+
/// </summary>
64+
protected override void ProcessRecord()
65+
{
66+
try
67+
{
68+
var sessionSvc = new SessionService();
69+
70+
if (!Enable.IsPresent && !Disable.IsPresent)
71+
throw new Exception("Either the Enable or Disable parameter must be supplied");
72+
73+
var request = new SessionSettings {
74+
AlternativeSpeedEnabled = Enable.IsPresent
75+
};
76+
77+
bool success = Task.Run(async () => await sessionSvc.Set(request)).Result;
78+
79+
if (success)
80+
WriteObject($"Alt speed settings {(Enable.IsPresent ? "enabled" : "disabled")} succesfully");
81+
}
82+
catch (Exception e)
83+
{
84+
ThrowTerminatingError(new ErrorRecord(new Exception(e.Message, e), null, ErrorCategory.OperationStopped, null));
85+
}
86+
}
87+
88+
/// <summary>
89+
/// Implements the <see cref="EndProcessing"/> method for <see cref="SetTransmissionAltSpeedLimitsCmdlet"/>.
90+
/// Retrieve all torrents
91+
/// </summary>
92+
protected override void EndProcessing()
93+
{
94+
95+
}
96+
}
97+
}

src/PsTransmission/Transmission.psd1

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
RootModule = 'Transmission.dll'
1313

1414
# Version number of this module.
15-
ModuleVersion = '1.0.7'
15+
ModuleVersion = '1.0.8'
1616

1717
# Supported PSEditions
1818
CompatiblePSEditions = 'Core'
@@ -92,7 +92,8 @@
9292
'Set-TransmissionTorrentsLocation',
9393
'Start-TransmissionTorrents',
9494
'Start-TransmissionTorrentsNow',
95-
'Stop-TransmissionTorrents'
95+
'Stop-TransmissionTorrents',
96+
'Set-TransmissionAltSpeedLimits'
9697
)
9798

9899
# Variables to export from this module

0 commit comments

Comments
 (0)