|
2 | 2 | title: 'Quickstart: Use .NET to create a pool and run a job'
|
3 | 3 | description: Follow this quickstart to run a C# app that uses the Batch .NET client library to create and run Batch pools, nodes, jobs, and tasks.
|
4 | 4 | ms.topic: quickstart
|
5 |
| -ms.date: 04/20/2023 |
| 5 | +ms.date: 04/28/2023 |
6 | 6 | ms.devlang: csharp
|
7 | 7 | ms.custom: mvc, devx-track-csharp, mode-api
|
8 | 8 | ---
|
@@ -118,36 +118,40 @@ Review the code to understand the steps in the [Azure Batch .NET Quickstart](htt
|
118 | 118 |
|
119 | 119 | ### Create service clients and upload resource files
|
120 | 120 |
|
121 |
| -1. To interact with the storage account, the app uses the Azure Storage Client Library for .NET to create a reference to the account with [CloudStorageAccount](/dotnet/api/microsoft.azure.storage.cloudstorageaccount), and from that creates a [CloudBlobClient](/dotnet/api/microsoft.azure.storage.blob.cloudblobclient). |
| 121 | +1. To interact with the storage account, the app uses the Azure Storage Blobs client library for .NET to create a [BlobServiceClient](/dotnet/api/azure.storage.blobs.blobserviceclient). |
122 | 122 |
|
123 | 123 | ```csharp
|
124 |
| - CloudBlobClient blobClient = CreateCloudBlobClient(StorageAccountName, StorageAccountKey); |
| 124 | + var sharedKeyCredential = new StorageSharedKeyCredential(storageAccountName, storageAccountKey); |
| 125 | + string blobUri = "https://" + storageAccountName + ".blob.core.windows.net"; |
| 126 | + |
| 127 | + var blobServiceClient = new BlobServiceClient(new Uri(blobUri), sharedKeyCredential); |
| 128 | + return blobServiceClient; |
125 | 129 | ```
|
126 | 130 |
|
127 |
| -1. The app uses the `blobClient` reference to create a container in the storage account and upload data files to the container. The files in storage are defined as Batch [ResourceFile](/dotnet/api/microsoft.azure.batch.resourcefile) objects that Batch can later download to the compute nodes. |
| 131 | +1. The app uses the `blobServiceClient` reference to create a container in the storage account and upload data files to the container. The files in storage are defined as Batch [ResourceFile](/dotnet/api/microsoft.azure.batch.resourcefile) objects that Batch can later download to the compute nodes. |
128 | 132 |
|
129 | 133 | ```csharp
|
130 |
| - List<string> inputFilePaths = new List<string> |
| 134 | + List<string> inputFilePaths = new() |
131 | 135 | {
|
132 | 136 | "taskdata0.txt",
|
133 | 137 | "taskdata1.txt",
|
134 | 138 | "taskdata2.txt"
|
135 | 139 | };
|
136 | 140 |
|
137 |
| - List<ResourceFile> inputFiles = new List<ResourceFile>(); |
| 141 | + var inputFiles = new List<ResourceFile>(); |
138 | 142 |
|
139 |
| - foreach (string filePath in inputFilePaths) |
| 143 | + foreach (var filePath in inputFilePaths) |
140 | 144 | {
|
141 |
| - inputFiles.Add(UploadFileToContainer(blobClient, inputContainerName, filePath)); |
| 145 | + inputFiles.Add(UploadFileToContainer(containerClient, inputContainerName, filePath)); |
142 | 146 | }
|
143 | 147 | ```
|
144 | 148 |
|
145 | 149 | 1. The app creates a [BatchClient](/dotnet/api/microsoft.azure.batch.batchclient) object to create and manage Batch pools, jobs, and tasks. The Batch client uses shared key authentication. Batch also supports Azure Active Directory (Azure AD) authentication.
|
146 | 150 |
|
147 | 151 | ```csharp
|
148 |
| - BatchSharedKeyCredentials cred = new BatchSharedKeyCredentials(BatchAccountUrl, BatchAccountName, BatchAccountKey); |
| 152 | + var cred = new BatchSharedKeyCredentials(BatchAccountUrl, BatchAccountName, BatchAccountKey); |
149 | 153 |
|
150 |
| - using (BatchClient batchClient = BatchClient.Open(cred)) |
| 154 | + using BatchClient batchClient = BatchClient.Open(cred); |
151 | 155 | ...
|
152 | 156 | ```
|
153 | 157 |
|
@@ -224,8 +228,10 @@ for (int i = 0; i < inputFiles.Count; i++)
|
224 | 228 | string inputFilename = inputFiles[i].FilePath;
|
225 | 229 | string taskCommandLine = String.Format("cmd /c type {0}", inputFilename);
|
226 | 230 |
|
227 |
| - CloudTask task = new CloudTask(taskId, taskCommandLine); |
228 |
| - task.ResourceFiles = new List<ResourceFile> { inputFiles[i] }; |
| 231 | + var task = new CloudTask(taskId, taskCommandLine) |
| 232 | + { |
| 233 | + ResourceFiles = new List<ResourceFile> { inputFiles[i] } |
| 234 | + }; |
229 | 235 | tasks.Add(task);
|
230 | 236 | }
|
231 | 237 |
|
|
0 commit comments