public async Task <Response <Device> > AddDeviceAsync(Device device) { Microsoft.Azure.Devices.Device requestDevice; try { //Console.WriteLine("New device:"); requestDevice = new Microsoft.Azure.Devices.Device(device.Id); requestDevice = await registryManager.AddDeviceAsync(requestDevice); return(new Response <Device>() { Success = true, ResponseObject = device }); } catch (DeviceAlreadyExistsException ex) { List <AzureException> exception = new List <AzureException>() { new AzureException() { Exception = ex, Message = ex.Message } }; return(new Response <Device>() { Success = true, ResponseObject = device, Exceptions = exception.ToArray() }); } }
public async void GetDeviceListFromAzure() { registryManager = RegistryManager.CreateFromConnectionString(connectionString); IQuery query = registryManager.CreateQuery("select * from devices"); List <Device> localDevices = new List <Device>(); Device currentDevice; try { while (query.HasMoreResults) { IEnumerable <Twin> devices = await query.GetNextAsTwinAsync(); devices.ToList().ForEach(x => { currentDevice = new Device() { Id = x.DeviceId, Status = (AzureIOT.Models.Status)x.Status, LastActive = x.LastActivityTime ?? DateTime.MinValue, CloudToDeviceMessages = x.CloudToDeviceMessageCount ?? x.CloudToDeviceMessageCount.Value, AuthType = (AzureIOT.Models.AuthTypes)(x.AuthenticationType ?? x.AuthenticationType), PrimaryThumbprint = x.X509Thumbprint.PrimaryThumbprint, SecondaryThumbprint = x.X509Thumbprint.SecondaryThumbprint }; localDevices.Add(currentDevice); currentDevice = null; }); } this.deviceResponse = new Response <List <Device> >() { Success = true, ResponseObject = localDevices }; } catch (Exception ex) { List <AzureException> azureException = new List <AzureException>() { new AzureException() { Exception = ex, Message = ex.Message } }; this.deviceResponse = new Response <List <Device> >() { Success = false, Exceptions = azureException.ToArray() }; } }
public void GetDeviceListFromAzure() { registryManager = RegistryManager.CreateFromConnectionString(connectionStringForPortal); List <Device> localDevices = new List <Device>(); IEnumerable <Microsoft.Azure.Devices.Device> azureDevice = new List <Microsoft.Azure.Devices.Device>();// = registryManager.GetDevicesAsync(100); Task task = Task.Run(() => { azureDevice = registryManager.GetDevicesAsync(100).Result; }); task.Wait(); Device currentDevice; try { foreach (var x in azureDevice) { currentDevice = new Device() { Id = x.Id, Status = (AzureIOT.Models.Status)x.Status, LastActive = x.ConnectionStateUpdatedTime, CloudToDeviceMessages = x.CloudToDeviceMessageCount, //AuthType = (AzureIOT.Models.AuthTypes)(x. ?? x.AuthenticationType), PrimaryThumbprint = x.Authentication != null ? x.Authentication.X509Thumbprint.PrimaryThumbprint : null, SecondaryThumbprint = x.Authentication != null ? x.Authentication.X509Thumbprint.SecondaryThumbprint : null, }; localDevices.Add(currentDevice); currentDevice = null; } this.deviceResponse = new Response <List <Device> >() { Success = true, ResponseObject = localDevices }; } catch (Exception ex) { List <AzureException> azureException = new List <AzureException>() { new AzureException() { Exception = ex, Message = ex.Message } }; this.deviceResponse = new Response <List <Device> >() { Success = false, Exceptions = azureException.ToArray() }; } }
public Device DeviceDetail(string DeviceId) { registryManager = RegistryManager.CreateFromConnectionString(connectionStringForPortal); List <Device> localDevices = new List <Device>(); IEnumerable <Microsoft.Azure.Devices.Device> azureDevice = new List <Microsoft.Azure.Devices.Device>();// = registryManager.GetDevicesAsync(100); Task task = Task.Run(() => { azureDevice = registryManager.GetDevicesAsync(100).Result; }); task.Wait(); try { Device currentDevice = new Device(); foreach (var x in azureDevice) { if (x.Id != DeviceId) { continue; } currentDevice = new Device() { Id = x.Id, Status = (AzureIOT.Models.Status)x.Status, LastActive = x.LastActivityTime, ConnectionStatus = (AzureIOT.Models.ConnectStatus)x.ConnectionState, CloudToDeviceMessages = x.CloudToDeviceMessageCount, //AuthType = (AzureIOT.Models.AuthTypes)(x. ?? x.AuthenticationType), PrimaryThumbprint = x.Authentication != null ? x.Authentication.X509Thumbprint.PrimaryThumbprint : null, SecondaryThumbprint = x.Authentication != null ? x.Authentication.X509Thumbprint.SecondaryThumbprint : null, }; } return(currentDevice); } catch (DeviceAlreadyExistsException ex) { List <AzureException> exception = new List <AzureException>() { new AzureException() { Exception = ex, Message = ex.Message } }; return(new Device() { }); } }
public Response <Device> AddDeviceAsync(Device device) { Microsoft.Azure.Devices.Device requestDevice; try { //Console.WriteLine("New device:"); requestDevice = new Microsoft.Azure.Devices.Device(device.Name); Task task = Task.Run(() => { requestDevice = registryManager.AddDeviceAsync(requestDevice).Result; }); task.Wait(); device.Name = requestDevice.Id; return(new Response <Device>() { Success = true, ResponseObject = device }); } catch (DeviceAlreadyExistsException ex) { List <AzureException> exception = new List <AzureException>() { new AzureException() { Exception = ex, Message = ex.Message } }; return(new Response <Device>() { Success = true, ResponseObject = device, Exceptions = exception.ToArray() }); } }
public Response <Device> InsertDevice(Device device) { device.Id = device.Name.Replace(" ", ""); return(this.AddDeviceAsync(device)); }
public Response <DeviceTelemetry> GetDeviceTelemetries(Device device) { throw new NotImplementedException(); }
public Response <Device> InsertDevice(Device device) { return(this.AddDeviceAsync(device).Result); }