Skip to content

Commit 7b7d495

Browse files
authored
Merge pull request #263160 from MicrosoftDocs/repo_sync_working_branch
Confirm merge from repo_sync_working_branch to main to sync with https://github.com/MicrosoftDocs/azure-docs (branch main)
2 parents 62bc47f + 05fa4fc commit 7b7d495

File tree

1 file changed

+23
-44
lines changed

1 file changed

+23
-44
lines changed

articles/notification-hubs/export-modify-registrations-bulk.md

Lines changed: 23 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ This section assumes you have the following entities:
4444
An input file contains a list of registrations serialized in XML, one per row. Using the Azure SDK, the following code example shows how to serialize the registrations and upload them to blob container:
4545

4646
```csharp
47-
private static void SerializeToBlob(BlobContainerClient container, RegistrationDescription[] descriptions)
47+
private static async Task SerializeToBlobAsync(BlobContainerClient container, RegistrationDescription[] descriptions)
4848
{
4949
StringBuilder builder = new StringBuilder();
5050
foreach (var registrationDescription in descriptions)
@@ -55,7 +55,7 @@ private static void SerializeToBlob(BlobContainerClient container, RegistrationD
5555
var inputBlob = container.GetBlobClient(INPUT_FILE_NAME);
5656
using (MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(builder.ToString())))
5757
{
58-
inputBlob.UploadAsync(stream);
58+
await inputBlob.UploadAsync(stream);
5959
}
6060
}
6161
```
@@ -74,16 +74,12 @@ static Uri GetOutputDirectoryUrl(BlobContainerClient container)
7474
BlobSasBuilder builder = new BlobSasBuilder(BlobSasPermissions.All, DateTime.UtcNow.AddDays(1));
7575
return container.GenerateSasUri(builder);
7676
}
77-
78-
79-
8077

8178
static Uri GetInputFileUrl(BlobContainerClient container, string filePath)
8279
{
8380
Console.WriteLine(container.CanGenerateSasUri);
8481
BlobSasBuilder builder = new BlobSasBuilder(BlobSasPermissions.Read, DateTime.UtcNow.AddDays(1));
8582
return container.GenerateSasUri(builder);
86-
8783
}
8884
```
8985

@@ -93,23 +89,19 @@ With the two input and output URLs, you can now start the batch job.
9389

9490
```csharp
9591
NotificationHubClient client = NotificationHubClient.CreateClientFromConnectionString(CONNECTION_STRING, HUB_NAME);
96-
var createTask = client.SubmitNotificationHubJobAsync(
97-
new NotificationHubJob {
98-
JobType = NotificationHubJobType.ImportCreateRegistrations,
99-
OutputContainerUri = outputContainerSasUri,
100-
ImportFileUri = inputFileSasUri
101-
}
102-
);
103-
createTask.Wait();
92+
var job = await client.SubmitNotificationHubJobAsync(
93+
new NotificationHubJob {
94+
JobType = NotificationHubJobType.ImportCreateRegistrations,
95+
OutputContainerUri = outputContainerSasUri,
96+
ImportFileUri = inputFileSasUri
97+
}
98+
);
10499

105-
var job = createTask.Result;
106100
long i = 10;
107101
while (i > 0 && job.Status != NotificationHubJobStatus.Completed)
108102
{
109-
var getJobTask = client.GetNotificationHubJobAsync(job.JobId);
110-
getJobTask.Wait();
111-
job = getJobTask.Result;
112-
Thread.Sleep(1000);
103+
job = await client.GetNotificationHubJobAsync(job.JobId);
104+
await Task.Delay(1000);
113105
i--;
114106
}
115107
```
@@ -135,18 +127,9 @@ The following sample code imports registrations into a notification hub.
135127

136128
```csharp
137129
using Microsoft.Azure.NotificationHubs;
138-
using Microsoft.WindowsAzure.Storage;
139-
using Microsoft.WindowsAzure.Storage.Blob;
140-
using System;
141-
using System.Collections.Generic;
142-
using System.Globalization;
143-
using System.IO;
144-
using System.Linq;
145-
using System.Runtime.Serialization;
130+
using Azure.Storage.Blobs;
131+
using Azure.Storage.Sas;
146132
using System.Text;
147-
using System.Threading;
148-
using System.Threading.Tasks;
149-
using System.Xml;
150133

151134
namespace ConsoleApplication1
152135
{
@@ -158,7 +141,7 @@ namespace ConsoleApplication1
158141
private static string STORAGE_ACCOUNT_CONNECTIONSTRING = "connectionstring";
159142
private static string CONTAINER_NAME = "containername";
160143

161-
static void Main(string[] args)
144+
static async Task Main(string[] args)
162145
{
163146
var descriptions = new[]
164147
{
@@ -168,45 +151,41 @@ namespace ConsoleApplication1
168151
new MpnsRegistrationDescription(@"http://dm2.notify.live.net/throttledthirdparty/01.00/12G9Ed13dLb5RbCii5fWzpFpAgAAAAADAQAAAAQUZm52OkJCMjg1QTg1QkZDMdUxREQFBlVTTkMwMQ"),
169152
};
170153

171-
// Get a reference to a container named "sample-container" and then create it
154+
// Get a reference to a container named "sample-container" and then create it
172155
BlobContainerClient container = new BlobContainerClient(STORAGE_ACCOUNT_CONNECTIONSTRING, CONTAINER_NAME);
173156

174-
container.CreateIfNotExistsAsync();
157+
await container.CreateIfNotExistsAsync();
175158

176-
SerializeToBlob(container, descriptions);
159+
await SerializeToBlobAsync(container, descriptions);
177160

178161
// TODO then create Sas
179162
var outputContainerSasUri = GetOutputDirectoryUrl(container);
180163

181-
BlobContainerClient inputfilecontainer = new BlobContainerClient(STORAGE_ACCOUNT_CONNECTIONSTRING, STORAGE_ACCOUNT_CONNECTIONSTRING + "/" + INPUT_FILE_NAME);
164+
BlobContainerClient inputcontainer = new BlobContainerClient(STORAGE_ACCOUNT_CONNECTIONSTRING, STORAGE_ACCOUNT_CONNECTIONSTRING + "/" + INPUT_FILE_NAME);
182165

183166
var inputFileSasUri = GetInputFileUrl(inputcontainer, INPUT_FILE_NAME);
184167

185168

186169
// Import this file
187170
NotificationHubClient client = NotificationHubClient.CreateClientFromConnectionString(CONNECTION_STRING, HUB_NAME);
188-
var createTask = client.SubmitNotificationHubJobAsync(
171+
var job = await client.SubmitNotificationHubJobAsync(
189172
new NotificationHubJob {
190173
JobType = NotificationHubJobType.ImportCreateRegistrations,
191174
OutputContainerUri = outputContainerSasUri,
192175
ImportFileUri = inputFileSasUri
193176
}
194177
);
195-
createTask.Wait();
196178

197-
var job = createTask.Result;
198179
long i = 10;
199180
while (i > 0 && job.Status != NotificationHubJobStatus.Completed)
200181
{
201-
var getJobTask = client.GetNotificationHubJobAsync(job.JobId);
202-
getJobTask.Wait();
203-
job = getJobTask.Result;
204-
Thread.Sleep(1000);
182+
job = await client.GetNotificationHubJobAsync(job.JobId);
183+
await Task.Delay(1000);
205184
i--;
206185
}
207186
}
208187

209-
private static void SerializeToBlob(BlobContainerClient container, RegistrationDescription[] descriptions)
188+
private static async Task SerializeToBlobAsync(BlobContainerClient container, RegistrationDescription[] descriptions)
210189
{
211190
StringBuilder builder = new StringBuilder();
212191
foreach (var registrationDescription in descriptions)
@@ -217,7 +196,7 @@ namespace ConsoleApplication1
217196
var inputBlob = container.GetBlobClient(INPUT_FILE_NAME);
218197
using (MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(builder.ToString())))
219198
{
220-
inputBlob.UploadAsync(stream);
199+
await inputBlob.UploadAsync(stream);
221200
}
222201
}
223202

0 commit comments

Comments
 (0)