| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. |
| | 3 | |
|
| | 4 | | using System.Collections.Generic; |
| | 5 | | using Azure.Iot.Hub.Service.Models; |
| | 6 | |
|
| | 7 | | namespace Azure.Iot.Hub.Service |
| | 8 | | { |
| | 9 | | /// <summary> |
| | 10 | | /// Helper functions for mutating the <see cref="ExportImportDevice"/> instance. |
| | 11 | | /// </summary> |
| | 12 | | internal static class ExportImportDeviceExtensions |
| | 13 | | { |
| | 14 | | /// <summary> |
| | 15 | | /// Initializes the <see cref="ExportImportDevice.Tags"/> property using provided values. |
| | 16 | | /// </summary> |
| | 17 | | public static ExportImportDevice WithTags(this ExportImportDevice device, IDictionary<string, object> tags) |
| | 18 | | { |
| 0 | 19 | | foreach (var tag in tags) |
| | 20 | | { |
| 0 | 21 | | device.Tags.Add(tag); |
| | 22 | | } |
| 80 | 23 | | return device; |
| | 24 | | } |
| | 25 | |
|
| | 26 | | /// <summary> |
| | 27 | | /// Initializes the <see cref="ExportImportDevice.Properties"/> property using provided values. |
| | 28 | | /// </summary> |
| | 29 | | public static ExportImportDevice WithPropertiesFrom(this ExportImportDevice device, TwinProperties properties) |
| | 30 | | { |
| | 31 | |
|
| 80 | 32 | | var container = new PropertyContainer(); |
| 80 | 33 | | if (properties != null) |
| | 34 | | { |
| 320 | 35 | | foreach (var property in properties.Desired) |
| | 36 | | { |
| 80 | 37 | | container.Desired.Add(property); |
| | 38 | | } |
| 0 | 39 | | foreach (var property in properties.Reported) |
| | 40 | | { |
| 0 | 41 | | container.Reported.Add(property); |
| | 42 | | } |
| | 43 | | } |
| | 44 | |
|
| 80 | 45 | | device.Properties = container; |
| | 46 | |
|
| 80 | 47 | | return device; |
| | 48 | | } |
| | 49 | |
|
| | 50 | | /// <summary> |
| | 51 | | /// Initializes the <see cref="ExportImportDevice.ParentScopes"/> property using provided values. |
| | 52 | | /// </summary> |
| | 53 | | public static ExportImportDevice WithParentScopes(this ExportImportDevice device, IList<string> parentScopes) |
| | 54 | | { |
| 0 | 55 | | foreach (var parentScope in parentScopes) |
| | 56 | | { |
| 0 | 57 | | device.ParentScopes.Add(parentScope); |
| | 58 | | } |
| 168 | 59 | | return device; |
| | 60 | | } |
| | 61 | | } |
| | 62 | | } |