Skip to content
This repository was archived by the owner on Nov 16, 2023. It is now read-only.

Commit 875aa33

Browse files
committed
Final changes, update comments.
1 parent c30480f commit 875aa33

File tree

2 files changed

+22
-21
lines changed

2 files changed

+22
-21
lines changed

iot-hub/Samples/device/ImportExportDevicesSample/ProcessImpExpCommands.cs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ namespace ImportExportDevices
1414
public static class IoTHubDevices
1515
{
1616

17-
1817
//generate NumToAdd devices and add them to the hub
1918
// to do this, generate each identity
2019
// * include authentication keys
@@ -215,8 +214,7 @@ public static async Task DeleteAllDevicesFromHub(string hubConnectionString,
215214
sb.AppendLine(JsonConvert.SerializeObject(device));
216215
});
217216

218-
// Step 2: Delete the blob if it already exists, then write the list in memory to the blob.
219-
217+
// Step 2: Delete the blob if it already exists, then write the list in memory to the blob.
220218
await blobToDelete.DeleteIfExistsAsync();
221219
using (CloudBlobStream stream = await blobToDelete.OpenWriteAsync())
222220
{
@@ -252,18 +250,19 @@ public static async Task DeleteAllDevicesFromHub(string hubConnectionString,
252250
}
253251

254252
//---------------------------------------------------------------------------------------
255-
// This shows how to export devices for an IoT Hub. Then import them to a new Hub.
253+
// This shows how to copy devices from one IoT Hub to another.
256254
// First, export the list from the Source hut to devices.txt (ExportDevices).
257255
// Next, read in that file. Each row is a serialized object;
258256
// read them into the generic list serializedDevices.
259257
// Delete the devices.txt in blob storage, because you're going to recreate it.
260-
// For each serializedDevice, deserialize it, set ImportMode to UPDATE,
258+
// For each serializedDevice, deserialize it, set ImportMode to CREATE,
261259
// reserialize it, and write it to a StringBuilder. The ImportMode field is what
262-
// tells the job framework to update each one.
260+
// tells the job framework to add each device.
263261
// Write the new StringBuilder to the block blob.
264262
// This essentially replaces the list with a list of devices that have ImportJob = Delete.
265263
// Call ImportDevicesAsync, which will read in the list in devices.txt, then add each one
266-
// because it doesn't already exist
264+
// because it doesn't already exist. If it already exists, it will write an entry to
265+
// the import error log and not add the new one.
267266
public static async Task CopyAllDevicesToNewHub(string sourceHubConnectionString,
268267
string destHubConnectionString, CloudBlobContainer cloudBlobContainer,
269268
string containerURI, string deviceListFile) {
@@ -323,8 +322,8 @@ public static async Task CopyAllDevicesToNewHub(string sourceHubConnectionString
323322
}
324323
}
325324

326-
// Step 3: Call import using the same blob to delete all devices.
327-
// Loads devices.txt and applies that change.
325+
// Step 3: Call import using the same blob to create all devices.
326+
// Loads devices.txt and adds the devices to the destination hub.
328327
RegistryManager registryManager =
329328
RegistryManager.CreateFromConnectionString(destHubConnectionString);
330329
JobProperties importJob =

iot-hub/Samples/device/ImportExportDevicesSample/Program.cs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
using System;
2-
using System.Threading.Tasks;
1+
using Microsoft.Azure.Storage;
32
using Microsoft.Azure.Storage.Blob;
4-
using Microsoft.Azure.Storage;
53
using Microsoft.Azure.Storage.RetryPolicies;
4+
using System;
65

76
namespace ImportExportDevices
87
{
98
public class Program
109
{
11-
//user variables -- add a config file and put these in settings?
1210

1311
//IoT Hub connection string. You can get this from the portal.
1412
// Log into https://azure.portal.com, go to Resources, find your hub and select it.
@@ -26,7 +24,7 @@ public class Program
2624
public static string storageAccountConnectionString = "<your storage account connection string>";
2725

2826
// Container used to hold the blob containing the list of import/export files.
29-
// This is a module-wide variable.
27+
// This is a module-wide variable. If this project doesn't find this container, it will create it.
3028
public static CloudBlobContainer cloudBlobContainer;
3129

3230
// Name of blob container holding the work data.
@@ -38,11 +36,11 @@ public class Program
3836

3937
public static void Main(string[] args)
4038
{
41-
//To use this sample, uncomment the bits you want to see run.
39+
//To use this sample, uncomment the bits you want to run.
4240

4341
//The size of the hub you are using should be able to manage the number of devices
4442
// you want to create and test with.
45-
//For example, if you want to create a million devices, don't use a hub with a Basic sku.
43+
//For example, if you want to create a million devices, don't use a hub with a Basic sku!
4644

4745
// You must run this; it creates the blob storage resource.
4846
string containerURI = PrepareStorageForImportExport();
@@ -51,27 +49,31 @@ public static void Main(string[] args)
5149
// Add devices to the hub; specify how many. This creates a number of devices
5250
// with partially random hub names.
5351
// This is a good way to test the import -- create a bunch of devices on one hub,
54-
// then use this the Copy feature to copy the devices to the other hub.
52+
// then use this the Copy feature to copy the devices to another hub.
5553
// Number of devices to create and add. Default is 10.
5654
//int NumToAdd = 5;
5755
//IoTHubDevices.GenerateAndAddDevices(IoTHubConnectionString, cloudBlobContainer,
5856
// containerURI, NumToAdd, deviceListFile).Wait();
5957

60-
//** you can use this if you want to add a bunch of devices, then dump them and look at them in a file (in blob storage).
58+
// This exports the devices to a file in blob storag.e
59+
// You can use this to add a bunch of new devices, then export them and look at them in a file (in blob storage).
6160
//Console.WriteLine("Read devices from the original hub, write to blob storage.");
6261
// Read the list of registered devices for the IoT Hub.
6362
// Write them to blob storage.
6463
//IoTHubDevices.ExportDevices(containerURI, IoTHubConnectionString).Wait();
6564

66-
Console.WriteLine("Copy devices from the original hub to the new hub.");
67-
// Copy devices from an existing hub to the new hub.
65+
Console.WriteLine("Copy devices from the original hub to a new hub.");
66+
// Copy devices from an existing hub to a new hub.
6867
IoTHubDevices.CopyAllDevicesToNewHub(IoTHubConnectionString, DestIoTHubConnectionString,
6968
cloudBlobContainer, containerURI, deviceListFile).Wait();
7069

71-
//** uncomment this if you want to delete all the devices registered to the original hub **
70+
//** uncomment this if you want to delete all the devices registered to a hub **
71+
72+
// Delete devices from the source hub.
7273
//Console.WriteLine("Delete all devices from the source hub.");
7374
//IoTHubDevices.DeleteAllDevicesFromHub(IoTHubConnectionString, cloudBlobContainer, containerURI, deviceListFile).Wait();
7475

76+
// Delete devices from the destination hub.
7577
//Console.WriteLine("Delete all devices from the destination hub.");
7678
//IoTHubDevices.DeleteAllDevicesFromHub(DestIoTHubConnectionString, cloudBlobContainer, containerURI, deviceListFile).Wait();
7779

0 commit comments

Comments
 (0)