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>()); } }
EdgeDevice(Device device, bool owned, IotHub iotHub, NestedEdgeConfig nestedEdgeConfig) { this.device = device; this.iotHub = iotHub; this.owned = owned; this.nestedEdgeConfig = nestedEdgeConfig; }
public static async Task <EdgeDevice> GetOrCreateIdentityAsync( string deviceId, NestedEdgeConfig nestedEdgeConfig, IotHub iotHub, AuthenticationType authType, X509Thumbprint x509Thumbprint, CancellationToken token) { Option <EdgeDevice> device = await GetIdentityAsync(deviceId, iotHub, token, nestedEdgeConfig : nestedEdgeConfig); EdgeDevice edgeDevice = await device.Match( d => { Log.Information( "Device '{Device}' already exists on hub '{IotHub}'", d.Id, iotHub.Hostname); return(Task.FromResult(d)); }, () => CreateIdentityAsync(deviceId, nestedEdgeConfig, iotHub, authType, x509Thumbprint, token)); return(edgeDevice); }
public static Task <EdgeDevice> CreateIdentityAsync( string deviceId, NestedEdgeConfig nestedEdgeConfig, IotHub iotHub, AuthenticationType authType, X509Thumbprint x509Thumbprint, CancellationToken token) { if (authType == AuthenticationType.SelfSigned && x509Thumbprint == null) { throw new ArgumentException("A device created with self-signed mechanism must provide an x509 thumbprint."); } return(Profiler.Run( async() => { Device device = await iotHub.CreateEdgeDeviceIdentityAsync(deviceId, nestedEdgeConfig.ParentDeviceId, authType, x509Thumbprint, token); return new EdgeDevice(device, true, iotHub, nestedEdgeConfig); }, "Created edge device '{Device}' on hub '{IotHub}'", deviceId, iotHub.Hostname)); }