public async Task <HttpResponseMessage> DeleteAllDevices() { return(await GetServiceResponseAsync(async() => { // note that you could also hardcode a query to delete a subset of devices var query = new DeviceListQuery() { Skip = 0, Take = 1000, SortColumn = "DeviceID", }; DeviceListQueryResult devices = await _deviceLogic.GetDevices(query); foreach (var d in devices.Results) { if (d.DeviceProperties != null && d.DeviceProperties.DeviceID != null) { string deviceId = d.DeviceProperties.DeviceID; // do this in serial so as not to overload anything Debug.Write("DELETING DEVICE: " + deviceId + "..."); await _deviceLogic.RemoveDeviceAsync(deviceId); Debug.WriteLine(" (Deleted)"); } } return true; })); }
//[RequirePermission(Permission.ViewTelemetry)] public async Task <ActionResult> Index() { var name = User.Identity.Name; var model = new DashboardModel(); var filters = new List <Infrastructure.Models.FilterInfo> { new Infrastructure.Models.FilterInfo() { ColumnName = "status", FilterType = FilterType.Status, FilterValue = "Running" } }; var query = new DeviceListQuery() { Skip = 0, Take = MaxDevicesToDisplayOnDashboard, SortColumn = "DeviceID", Filters = filters }; DeviceListQueryResult queryResult = await _deviceLogic.GetDevices(query); if ((queryResult != null) && (queryResult.Results != null)) { foreach (DeviceModel devInfo in queryResult.Results) { string deviceId; try { deviceId = devInfo.DeviceProperties.DeviceID; } catch (DeviceRequiredPropertyNotFoundException) { continue; } model.DeviceIdsForDropdown.Add(new StringPair(deviceId, deviceId)); } } // Set key to empty if passed value 0 from arm template string key = _configProvider.GetConfigurationSettingValue("MapApiQueryKey"); model.MapApiQueryKey = key.Equals("0") ? string.Empty : key; return(View(model)); }
public async Task <HttpResponseMessage> GetDeviceLocationData() { return(await GetServiceResponseAsync <DeviceListLocationsModel>(async() => { var query = new DeviceListQuery() { Skip = 0, Take = MAX_DEVICES_TO_DISPLAY_ON_DASHBOARD, SortColumn = "DeviceID" }; DeviceListQueryResult queryResult = await _deviceLogic.GetDevices(query); DeviceListLocationsModel dataModel = _deviceLogic.ExtractLocationsData(queryResult.Results); return dataModel; }, false)); }
public async Task <ActionResult> Index() { var model = new DashboardModel(); List <Infrastructure.Models.FilterInfo> filters = new List <Infrastructure.Models.FilterInfo>(); filters.Add(new Infrastructure.Models.FilterInfo() { ColumnName = "status", FilterType = FilterType.Status, FilterValue = "Running" }); var query = new DeviceListQuery() { Skip = 0, Take = MaxDevicesToDisplayOnDashboard, SortColumn = "DeviceID", Filters = filters }; DeviceListQueryResult queryResult = await _deviceLogic.GetDevices(query); if ((queryResult != null) && (queryResult.Results != null)) { foreach (dynamic devInfo in queryResult.Results) { string deviceId; try { deviceId = DeviceSchemaHelper.GetDeviceID(devInfo); } catch (DeviceRequiredPropertyNotFoundException) { continue; } model.DeviceIdsForDropdown.Add(new StringPair(deviceId, deviceId)); } } model.MapApiQueryKey = _configProvider.GetConfigurationSettingValue("MapApiQueryKey"); return(View(model)); }
private async Task <List <DeviceModel> > LoadAllDevicesAsync() { var query = new DeviceListQuery() { Skip = 0, Take = MAX_DEVICES_TO_DISPLAY_ON_DASHBOARD, SortColumn = "DeviceID" }; string deviceId; var devices = new List <DeviceModel>(); DeviceListQueryResult queryResult = await _deviceLogic.GetDevices(query); if ((queryResult != null) && (queryResult.Results != null)) { bool? enabledState; DeviceProperties props; foreach (var devInfo in queryResult.Results) { try { deviceId = devInfo.DeviceProperties.DeviceID; props = devInfo.DeviceProperties; enabledState = props.HubEnabledState; } catch (NullReferenceException) { continue; } if (!string.IsNullOrWhiteSpace(deviceId)) { devices.Add(devInfo); } } } return(devices); }
private async Task <List <dynamic> > LoadAllDevicesAsync() { var query = new DeviceListQuery() { Skip = 0, Take = MAX_DEVICES_TO_DISPLAY_ON_DASHBOARD, SortColumn = "DeviceID" }; string deviceId; var devices = new List <dynamic>(); DeviceListQueryResult queryResult = await _deviceLogic.GetDevices(query); if ((queryResult != null) && (queryResult.Results != null)) { string enabledState = ""; dynamic props = null; foreach (dynamic devInfo in queryResult.Results) { try { deviceId = DeviceSchemaHelper.GetDeviceID(devInfo); props = DeviceSchemaHelper.GetDeviceProperties(devInfo); enabledState = props.HubEnabledState; } catch (DeviceRequiredPropertyNotFoundException) { continue; } if (!string.IsNullOrWhiteSpace(deviceId)) { devices.Add(devInfo); } } } return(devices); }