Skip to content

Commit 72c3cd0

Browse files
author
jasper-schneider
committed
Incorporate feedback
1 parent ee7467c commit 72c3cd0

File tree

8 files changed

+29
-27
lines changed

8 files changed

+29
-27
lines changed

src/ResourceManager/Batch/Commands.Batch.Test/Files/GetBatchTaskFileContentCommandTests.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,6 @@ public void GetBatchTaskFileParametersTest()
9393
cmdlet.TaskName = "task";
9494
cmdlet.Name = fileName;
9595

96-
Assert.Throws<ArgumentNullException>(() => cmdlet.ExecuteCmdlet());
97-
98-
// File in required local path
99-
cmdlet.DestinationPath = "localFile.txt";
100-
10196
try
10297
{
10398
// Verify no exceptions occur

src/ResourceManager/Batch/Commands.Batch.Test/ScenarioTests/FileTests.ps1

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,11 @@ function Test-GetTaskFileContentByName
153153
param([string]$accountName, [string]$wiName, [string]$jobName, [string]$taskName, [string]$taskFileName, [string]$fileContent)
154154

155155
$context = Get-AzureBatchAccountKeys -Name $accountName
156-
$path = "localFile.txt"
157156
$stream = New-Object System.IO.MemoryStream
158157

159158
try
160159
{
161-
Get-AzureBatchTaskFileContent_ST -WorkItemName $wiName -JobName $jobName -TaskName $taskName -Name $taskFileName -DestinationPath $path -BatchContext $context -MemStream $stream
160+
Get-AzureBatchTaskFileContent_ST -WorkItemName $wiName -JobName $jobName -TaskName $taskName -Name $taskFileName -BatchContext $context -MemStream $stream
162161

163162
$stream.Position = 0
164163
$sr = New-Object System.IO.StreamReader $stream
@@ -180,7 +179,7 @@ function Test-GetTaskFileContentByName
180179
$stream = New-Object System.IO.MemoryStream
181180
try
182181
{
183-
Get-AzureBatchTaskFileContent_ST -WorkItemName $wiName -JobName $jobName -TaskName $taskName -Name $taskFileName -DestinationPath $path -BatchContext $context -MemStream $stream
182+
Get-AzureBatchTaskFileContent_ST -WorkItemName $wiName -JobName $jobName -TaskName $taskName -Name $taskFileName -BatchContext $context -MemStream $stream
184183

185184
$stream.Position = 0
186185
$sr = New-Object System.IO.StreamReader $stream
@@ -208,13 +207,12 @@ function Test-GetTaskFileContentPipeline
208207
param([string]$accountName, [string]$wiName, [string]$jobName, [string]$taskName, [string]$taskFileName, [string]$fileContent)
209208

210209
$context = Get-AzureBatchAccountKeys -Name $accountName
211-
$path = "localFile.txt"
212210
$stream = New-Object System.IO.MemoryStream
213211

214212
try
215213
{
216214
$taskFile = Get-AzureBatchTaskFile_ST -WorkItemName $wiName -JobName $jobName -TaskName $taskName -Name $taskFileName -BatchContext $context
217-
$taskFile | Get-AzureBatchTaskFileContent_ST -DestinationPath $path -BatchContext $context -MemStream $stream
215+
$taskFile | Get-AzureBatchTaskFileContent_ST -BatchContext $context -MemStream $stream
218216

219217
$stream.Position = 0
220218
$sr = New-Object System.IO.StreamReader $stream

src/ResourceManager/Batch/Commands.Batch/Files/GetBatchTaskFileCommand.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,26 @@ public class GetBatchTaskFileCommand : BatchObjectModelCmdletBase
2525
{
2626
private int maxCount = Constants.DefaultMaxCount;
2727

28-
[Parameter(Position = 0, ParameterSetName = Constants.NameParameterSet, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The name of the WorkItem.")]
28+
[Parameter(Position = 0, ParameterSetName = Constants.NameParameterSet, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The name of the workitem which contains the specified target task.")]
2929
[Parameter(Position = 0, ParameterSetName = Constants.ODataFilterParameterSet, Mandatory = true, ValueFromPipelineByPropertyName = true)]
3030
[ValidateNotNullOrEmpty]
3131
public string WorkItemName { get; set; }
3232

33-
[Parameter(Position = 1, ParameterSetName = Constants.NameParameterSet, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The name of the Job.")]
33+
[Parameter(Position = 1, ParameterSetName = Constants.NameParameterSet, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The name of the job containing the specified target task.")]
3434
[Parameter(Position = 1, ParameterSetName = Constants.ODataFilterParameterSet, Mandatory = true, ValueFromPipelineByPropertyName = true)]
3535
[ValidateNotNullOrEmpty]
3636
public string JobName { get; set; }
3737

38-
[Parameter(Position = 2, ParameterSetName = Constants.NameParameterSet, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The name of the Task.")]
38+
[Parameter(Position = 2, ParameterSetName = Constants.NameParameterSet, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The name of the task.")]
3939
[Parameter(Position = 2, ParameterSetName = Constants.ODataFilterParameterSet, Mandatory = true, ValueFromPipelineByPropertyName = true)]
4040
[ValidateNotNullOrEmpty]
4141
public string TaskName { get; set; }
4242

43-
[Parameter(Position = 3, ParameterSetName = Constants.NameParameterSet, HelpMessage = "The name of the Task file.")]
43+
[Parameter(Position = 3, ParameterSetName = Constants.NameParameterSet, HelpMessage = "The name of the task file to retrieve.")]
4444
[ValidateNotNullOrEmpty]
4545
public string Name { get; set; }
4646

47-
[Parameter(Position = 0, ParameterSetName = Constants.ParentObjectParameterSet, ValueFromPipeline = true, HelpMessage = "The Task to query for files.")]
47+
[Parameter(Position = 0, ParameterSetName = Constants.ParentObjectParameterSet, ValueFromPipeline = true, HelpMessage = "The Task object to use as the basis for the file query.")]
4848
[ValidateNotNullOrEmpty]
4949
public PSCloudTask Task { get; set; }
5050

src/ResourceManager/Batch/Commands.Batch/Files/GetBatchTaskFileContentCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public class GetBatchTaskFileContentCommand : BatchObjectModelCmdletBase
4444
[ValidateNotNullOrEmpty]
4545
public PSTaskFile InputObject { get; set; }
4646

47-
[Parameter(Mandatory = true, HelpMessage = "The destination path where the Task file will be downloaded.")]
47+
[Parameter(HelpMessage = "The path to the directory where the Task file will be downloaded.")]
4848
[ValidateNotNullOrEmpty]
4949
public string DestinationPath { get; set; }
5050

src/ResourceManager/Batch/Commands.Batch/Models/BatchClient.Files.cs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
using System.Linq;
1616
using Microsoft.Azure.Batch;
17+
using Microsoft.Azure.Batch.Protocol.Entities;
1718
using Microsoft.Azure.Commands.Batch.Models;
1819
using Microsoft.Azure.Commands.Batch.Properties;
1920
using System;
@@ -94,7 +95,7 @@ public IEnumerable<PSTaskFile> ListTaskFiles(ListTaskFileOptions options)
9495
}
9596

9697
/// <summary>
97-
/// Downloads a Task file to the local machine
98+
/// Downloads a Task file using the specified options.
9899
/// </summary>
99100
/// <param name="options">The download options</param>
100101
public void DownloadTaskFile(DownloadTaskFileOptions options)
@@ -110,11 +111,6 @@ public void DownloadTaskFile(DownloadTaskFileOptions options)
110111
throw new ArgumentNullException(Resources.GBTFC_NoTaskFileSpecified);
111112
}
112113

113-
if (string.IsNullOrWhiteSpace(options.DestinationPath))
114-
{
115-
throw new ArgumentNullException(Resources.GBTFC_NoDestinationPath);
116-
}
117-
118114
ITaskFile taskFile = null;
119115
if (options.TaskFile == null)
120116
{
@@ -128,7 +124,20 @@ public void DownloadTaskFile(DownloadTaskFileOptions options)
128124
taskFile = options.TaskFile.omObject;
129125
}
130126

131-
WriteVerbose(string.Format(Resources.GBTFC_Downloading, taskFile.Name, options.DestinationPath));
127+
string path = null;
128+
// The task file object's name is a relative path that includes directories.
129+
string fileName = Path.GetFileName(taskFile.Name);
130+
if (string.IsNullOrWhiteSpace(options.DestinationPath))
131+
{
132+
// If no destination is specified, just save the file to the local directory
133+
path = fileName;
134+
}
135+
else
136+
{
137+
path = Path.Combine(options.DestinationPath, fileName);
138+
}
139+
140+
WriteVerbose(string.Format(Resources.GBTFC_Downloading, taskFile.Name, path));
132141
if (options.Stream != null)
133142
{
134143
// Used for testing.
@@ -137,7 +146,7 @@ public void DownloadTaskFile(DownloadTaskFileOptions options)
137146
}
138147
else
139148
{
140-
using (FileStream fs = new FileStream(options.DestinationPath, FileMode.Create))
149+
using (FileStream fs = new FileStream(path, FileMode.Create))
141150
{
142151
taskFile.CopyToStream(fs, options.AdditionalBehaviors);
143152
}

src/ResourceManager/Batch/Commands.Batch/Models/DownloadTaskFileOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public class DownloadTaskFileOptions
5151
public PSTaskFile TaskFile { get; set; }
5252

5353
/// <summary>
54-
/// The destination path where the Task file will be downloaded
54+
/// The path to the directory where the Task file will be downloaded
5555
/// </summary>
5656
public string DestinationPath { get; set; }
5757

src/ResourceManager/Batch/Commands.Batch/Properties/Resources.Designer.cs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ResourceManager/Batch/Commands.Batch/Properties/Resources.resx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@
157157
<value>Getting all Pools associated with the Batch account. </value>
158158
</data>
159159
<data name="GBTFC_Downloading" xml:space="preserve">
160-
<value>Downloading Task file "{0}" to local path: {1}</value>
160+
<value>Downloading Task file "{0}" to: {1}</value>
161161
</data>
162162
<data name="GBTFC_NoDestinationPath" xml:space="preserve">
163163
<value>No destination path was specified. Supply a path where the Task file should be downloaded.</value>

0 commit comments

Comments
 (0)