public static async Task <Option <EdgeDevice> > GetIdentityAsync( string deviceId, IotHub iotHub, CancellationToken token, bool takeOwnership = false, NestedEdgeConfig nestedEdgeConfig = default(NestedEdgeConfig)) { Device device = await iotHub.GetDeviceIdentityAsync(deviceId, token); if (device != null) { if (nestedEdgeConfig != default(NestedEdgeConfig)) { await nestedEdgeConfig.ParentDeviceId.ForEachAsync(async p => { Device parentDevice = await iotHub.GetDeviceIdentityAsync(p, token); device.ParentScopes.Add(parentDevice.Scope); }); } if (!device.Capabilities.IotEdge) { throw new InvalidOperationException($"Device '{device.Id}' exists, but is not an edge device"); } return(Option.Some(new EdgeDevice(device, takeOwnership, iotHub, nestedEdgeConfig))); } else { return(Option.None <EdgeDevice>()); } }
public static async Task <EdgeDevice> GetOrCreateIdentityAsync( string deviceId, IotHub iotHub, CancellationToken token) { Device device = await iotHub.GetDeviceIdentityAsync(deviceId, token); if (device != null) { if (!device.Capabilities.IotEdge) { throw new InvalidOperationException($"Device '{device.Id}' exists, but is not an edge device"); } Log.Information( "Device '{Device}' already exists on hub '{IotHub}'", device.Id, iotHub.Hostname); return(new EdgeDevice(device, false, iotHub)); } else { return(await CreateIdentityAsync(deviceId, iotHub, token)); } }
public static async Task <Option <EdgeDevice> > GetIdentityAsync( string deviceId, IotHub iotHub, CancellationToken token) { Device device = await iotHub.GetDeviceIdentityAsync(deviceId, token); if (device != null) { if (!device.Capabilities.IotEdge) { throw new InvalidOperationException($"Device '{device.Id}' exists, but is not an edge device"); } return(Option.Some(new EdgeDevice(device, false, iotHub))); } else { return(Option.None <EdgeDevice>()); } }