Skip to content

Commit 3926274

Browse files
authored
Update C# samples (#278)
- Use Microsoft.Azure.Batch 12.0. - Use Microsoft.Azure.Batch.FileStaging 8.3. - Use Microsoft.Azure.Batch.Conventions.Files 3.5.1.
1 parent 2faacfc commit 3926274

File tree

26 files changed

+68
-88
lines changed

26 files changed

+68
-88
lines changed

CONTRIBUTING.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ You can contribute to [Azure batch samples](https://github.com/Azure/azure-batch
1515
#### Building the CSharp samples
1616
To build all the CSharp samples without opening Visual Studio, you can use this simple script:
1717
```
18-
for /R %f in (*.sln) do (nuget restore "%f" & msbuild /m "%f")
18+
for /R %f in (*.sln) do (dotnet build "%f")
1919
```
2020

2121
If you want to write the output of the build to a file you can tack on ` >> mybuild.tmp` to the end of the command.
@@ -24,5 +24,4 @@ If you want to write the output of the build to a file you can tack on ` >> mybu
2424
The Azure Batch samples should be kept up to date with the latest Azure.Batch NuGet package.
2525

2626
##### Using a text replace
27-
The following commands can be used to perform the textual replace: `rep.exe -find:"<PackageReference Include=\"Microsoft.Azure.Batch\" Version=\"8.1.2\" />" -replace:"<PackageReference Include=\"Microsoft.Azure.Batch\" Version=\"9.0.0\" />" -r *.csproj`
28-
27+
The following commands can be used to perform the textual replace: `rep.exe -find:"<PackageReference Include=\"Microsoft.Azure.Batch\" Version=\"10.0.0\" />" -replace:"<PackageReference Include=\"Microsoft.Azure.Batch\" Version=\"12.0.0\" />" -r *.csproj`

CSharp/AccountManagement/AccountManagement.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
</ItemGroup>
1212

1313
<ItemGroup>
14-
<PackageReference Include="Microsoft.Azure.Management.Batch" Version="7.0.0" />
15-
<PackageReference Include="Microsoft.IdentityModel.Clients.ActiveDirectory" Version="4.4.2" />
14+
<PackageReference Include="Microsoft.Azure.Management.Batch" Version="9.0.0" />
15+
<PackageReference Include="Microsoft.IdentityModel.Clients.ActiveDirectory" Version="5.2.0" />
1616
<PackageReference Include="Microsoft.Azure.Management.ResourceManager" Version="2.0.0-preview" />
1717
</ItemGroup>
1818

CSharp/ArticleProjects/ApplicationInsights/TopNWords/TopNWords.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
</ItemGroup>
1515

1616
<ItemGroup>
17-
<PackageReference Include="Microsoft.Azure.Batch" Version="10.0.0" />
18-
<PackageReference Include="Microsoft.Azure.Batch.FileStaging" Version="8.2.0" />
17+
<PackageReference Include="Microsoft.Azure.Batch" Version="12.0.0" />
18+
<PackageReference Include="Microsoft.Azure.Batch.FileStaging" Version="8.3.0" />
1919
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="2.1.0" />
2020
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.1.0" />
21-
<PackageReference Include="WindowsAzure.Storage" Version="9.2.0" />
21+
<PackageReference Include="WindowsAzure.Storage" Version="9.3.3" />
2222
<PackageReference Include="Microsoft.ApplicationInsights.WindowsServer" Version="2.3.0" />
2323
</ItemGroup>
2424

CSharp/ArticleProjects/EfficientListQueries/EfficientListQueries.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
</ItemGroup>
1212

1313
<ItemGroup>
14-
<PackageReference Include="Microsoft.Azure.Batch" Version="10.0.0" />
14+
<PackageReference Include="Microsoft.Azure.Batch" Version="12.0.0" />
1515
</ItemGroup>
1616

1717
</Project>

CSharp/ArticleProjects/JobPrepRelease/JobPrepRelease.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
</ItemGroup>
1212

1313
<ItemGroup>
14-
<PackageReference Include="Microsoft.Azure.Batch" Version="10.0.0" />
14+
<PackageReference Include="Microsoft.Azure.Batch" Version="12.0.0" />
1515
</ItemGroup>
1616

1717
</Project>

CSharp/ArticleProjects/MultiInstanceTasks/MultiInstanceTasks.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
</ItemGroup>
2424

2525
<ItemGroup>
26-
<PackageReference Include="Microsoft.Azure.Batch" Version="10.0.0" />
27-
<PackageReference Include="WindowsAzure.Storage" Version="9.2.0" />
26+
<PackageReference Include="Microsoft.Azure.Batch" Version="12.0.0" />
27+
<PackageReference Include="WindowsAzure.Storage" Version="9.3.3" />
2828
</ItemGroup>
2929

3030
</Project>

CSharp/ArticleProjects/ParallelTasks/ParallelTasks.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
</ItemGroup>
1212

1313
<ItemGroup>
14-
<PackageReference Include="Microsoft.Azure.Batch" Version="10.0.0" />
14+
<PackageReference Include="Microsoft.Azure.Batch" Version="12.0.0" />
1515
</ItemGroup>
1616

1717
</Project>

CSharp/ArticleProjects/PersistOutputs/BatchExtensions.cs

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Linq;
66
using Batch.Common;
77
using Conventions.Files;
8+
using Microsoft.WindowsAzure.Storage;
89

910
public static class BatchExtensions
1011
{
@@ -43,22 +44,20 @@ public static IEnumerable<CloudTask> CompletedTasks(this CloudJob job)
4344

4445
public static CloudTask WithOutputFile(
4546
this CloudTask task,
47+
CloudJob job,
4648
string pattern,
4749
string containerUrl,
4850
JobOutputKind outputKind,
4951
OutputFileUploadCondition uploadCondition)
5052
{
51-
Func<string> pathFunc = () =>
52-
{
53-
bool patternContainsWildcard = pattern.Contains("*");
54-
55-
return patternContainsWildcard ? $"${outputKind}" : $"${outputKind}\\{pattern}";
56-
};
53+
var outputBase = job.GetOutputStoragePath(outputKind);
54+
bool patternContainsWildcard = pattern.Contains("*");
55+
var path = patternContainsWildcard ? outputBase : $"{outputBase}/{pattern}";
5756

5857
return task.WithOutputFile(
5958
pattern,
6059
containerUrl,
61-
pathFunc,
60+
path,
6261
uploadCondition);
6362
}
6463

@@ -69,34 +68,29 @@ public static CloudTask WithOutputFile(
6968
TaskOutputKind outputKind,
7069
OutputFileUploadCondition uploadCondition)
7170
{
72-
Func<string> pathFunc = () =>
73-
{
74-
bool patternContainsWildcard = pattern.Contains("*");
75-
76-
return patternContainsWildcard ? $"{task.Id}\\${outputKind}" : $"{task.Id}\\${outputKind}\\{pattern}";
77-
};
71+
var outputBase = task.GetOutputStoragePath(outputKind);
72+
bool patternContainsWildcard = pattern.Contains("*");
73+
var path = patternContainsWildcard ? outputBase : $"{outputBase}/{pattern}";
7874

7975
return task.WithOutputFile(
8076
pattern,
8177
containerUrl,
82-
pathFunc,
78+
path,
8379
uploadCondition);
8480
}
8581

8682
private static CloudTask WithOutputFile(
8783
this CloudTask task,
8884
string pattern,
8985
string containerUrl,
90-
Func<string> pathFunc,
86+
string path,
9187
OutputFileUploadCondition uploadCondition)
9288
{
9389
if (task.OutputFiles == null)
9490
{
9591
task.OutputFiles = new List<OutputFile>();
9692
}
9793

98-
string path = pathFunc();
99-
10094
task.OutputFiles.Add(
10195
new OutputFile(
10296
filePattern: pattern,

CSharp/ArticleProjects/PersistOutputs/OutputFilesExample.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -183,19 +183,19 @@ public static async Task<CloudBlobContainer> RunWithConventions(
183183
private static async Task CreatePoolAsync(BatchClient batchClient, string poolId, int nodeCount)
184184
{
185185
Func<ImageReference, bool> imageScanner = imageRef =>
186-
imageRef.Publisher == "MicrosoftWindowsServer" &&
187-
imageRef.Offer == "WindowsServer" &&
188-
imageRef.Sku.Contains("2012-R2-Datacenter");
186+
imageRef.Publisher.Equals("MicrosoftWindowsServer", StringComparison.InvariantCultureIgnoreCase) &&
187+
imageRef.Offer.Equals("WindowsServer", StringComparison.InvariantCultureIgnoreCase) &&
188+
imageRef.Sku.IndexOf("2012-R2-Datacenter", StringComparison.InvariantCultureIgnoreCase) > -1;
189189

190-
SampleHelpers.SkuAndImage skuAndImage = await SampleHelpers.GetNodeAgentSkuReferenceAsync(batchClient, imageScanner);
190+
ImageInformation imageInfo = await SampleHelpers.GetNodeAgentSkuReferenceAsync(batchClient, imageScanner);
191191

192192
// Create and configure an unbound pool.
193193
CloudPool pool = batchClient.PoolOperations.CreatePool(poolId: poolId,
194194
virtualMachineSize: "standard_d1_v2",
195195
targetDedicatedComputeNodes: nodeCount,
196196
virtualMachineConfiguration: new VirtualMachineConfiguration(
197-
skuAndImage.Image,
198-
skuAndImage.Sku.Id));
197+
imageInfo.ImageReference,
198+
imageInfo.NodeAgentSkuId));
199199

200200
// Commit the pool to the Batch service
201201
await GettingStartedCommon.CreatePoolIfNotExistAsync(batchClient, pool);

CSharp/ArticleProjects/PersistOutputs/PersistOutputs.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
</ItemGroup>
1818

1919
<ItemGroup>
20-
<PackageReference Include="Microsoft.Azure.Batch" Version="10.0.0" />
21-
<PackageReference Include="Microsoft.Azure.Batch.Conventions.Files" Version="3.3.0" />
20+
<PackageReference Include="Microsoft.Azure.Batch" Version="12.0.0" />
21+
<PackageReference Include="Microsoft.Azure.Batch.Conventions.Files" Version="3.5.1" />
2222

2323
</ItemGroup>
2424

0 commit comments

Comments
 (0)