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",
                };

                var devices = await _deviceLogic.GetDevices(query);

                foreach (var d in devices.Results)
                {
                    if (d.DeviceProperties != null && d.DeviceProperties.DeviceID != null)
                    {
                        string deviceId = DeviceSchemaHelper.GetDeviceID(d);

                        // do this in serial so as not to overload anything
                        Debug.Write("DELETING DEVICE: " + deviceId + "...");
                        await _deviceLogic.RemoveDeviceAsync(deviceId);
                        Debug.WriteLine("  (Deleted)");
                    }
                }
                return true;
            }));
        }
        public async Task <HttpResponseMessage> GetDevices([FromBody] JObject requestData)
        {
            var dataTableRequest = requestData.ToObject <DataTablesRequest>();
            var sortColumnIndex  = dataTableRequest.SortColumns[0].ColumnIndex;

            var listQuery = new DeviceListQuery()
            {
                SortOrder  = dataTableRequest.SortColumns[0].SortOrder,
                SortColumn = dataTableRequest.Columns[sortColumnIndex].Name,

                SearchQuery = dataTableRequest.Search.Value,

                Filters = dataTableRequest.Filters,

                Skip = dataTableRequest.Start,
                Take = dataTableRequest.Length
            };

            return(await GetServiceResponseAsync <DataTablesResponse>(async() =>
            {
                var queryResult = await _deviceLogic.GetDevices(listQuery);

                var dataTablesResponse = new DataTablesResponse()
                {
                    Draw = dataTableRequest.Draw,
                    RecordsTotal = queryResult.TotalDeviceCount,
                    RecordsFiltered = queryResult.TotalFilteredCount,
                    Data = queryResult.Results.ToArray()
                };

                return dataTablesResponse;
            }, false));
        }
Esempio n. 3
0
        public async Task <ActionResult> Index()
        {
            string                deviceId;
            DashboardModel        model;
            DeviceListQuery       query;
            DeviceListQueryResult queryResult;

            model = new DashboardModel();

            query = new DeviceListQuery()
            {
                Skip       = 0,
                Take       = MaxDevicesToDisplayOnDashboard,
                SortColumn = "DeviceID"
            };

            //The results of this query are used for populating the dropdown
            //As well as extracting location data. We want to include disabled
            //devices on the map, but not in the dropdown. The filters used
            //IN the query are apply additively to a "column". As a result, we
            //cannot filter on enabled AND disabled because the filters are
            //mutually exclusive. Also we cannot filter on !Pending. So to get
            //all that we need for both uses we need to just get all devices up
            //to the Take value and filter manually in the loop. The map will
            //filter out unregistered devices by virtue of their not having
            //location data.
            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.IsNullOrEmpty(deviceId) && !string.IsNullOrWhiteSpace(enabledState) && enabledState.ToLower() == "true")
                    {
                        model.DeviceIdsForDropdown.Add(new StringPair(deviceId, deviceId));
                    }
                }
            }

            model.DeviceLocations = _deviceLogic.ExtractLocationsData(queryResult.Results);
            model.MapApiQueryKey  = _configProvider.GetConfigurationSettingValue("MapApiQueryKey");

            return(View(model));
        }
Esempio n. 4
0
        private async Task <List <DeviceModel> > GetDevices()
        {
            var query = new DeviceListQuery
            {
                Take = 1000
            };

            var devices = await _deviceLogic.GetDevices(query);

            return(devices.Results);
        }
Esempio n. 5
0
        private async Task <List <dynamic> > GetDevices()
        {
            var query = new DeviceListQuery
            {
                Take = 1000
            };

            var devices = await this._deviceLogic.GetDevices(query);

            return(devices.Results);
        }
Esempio n. 6
0
        //[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));
        }
Esempio n. 7
0
        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));
        }
        public async Task <HttpResponseMessage> GetDevicesAsync(
            [FromUri] string search            = null,
            [FromUri] string sortColumn        = null,
            [FromUri] QuerySortOrder sortOrder = QuerySortOrder.Ascending,
            [FromUri] int skip = 0,
            [FromUri] int take = 50,
            [FromUri] string[] filterColumn   = null,
            [FromUri] FilterType[] filterType = null,
            [FromUri] string[] filterValue    = null)
        {
            var filters = new List <FilterInfo>();

            if (filterColumn != null && filterType != null && filterValue != null)
            {
                // valid filters must send ALL three values--ignore unmatched extras
                int validFiltersCount = Math.Min(filterColumn.Length, Math.Min(filterType.Length, filterValue.Length));
                for (int i = 0; i < validFiltersCount; ++i)
                {
                    var f = new FilterInfo()
                    {
                        ColumnName  = filterColumn[i],
                        FilterType  = filterType[i],
                        FilterValue = filterValue[i]
                    };

                    filters.Add(f);
                }
            }

            var q = new DeviceListQuery()
            {
                SearchQuery = search,
                SortColumn  = sortColumn,
                SortOrder   = sortOrder,
                Skip        = skip,
                Take        = take,
                Filters     = filters
            };

            return(await GetServiceResponseAsync(async() => (await _deviceLogic.GetDevices(q)).Results));
        }
Esempio n. 10
0
        /// <summary>
        /// Searches the DeviceProperties of all devices in the DocumentDB, sorts them and pages based on the provided values
        /// </summary>
        /// <param name="query">Object containing search, filtering, paging, and other info</param>
        /// <returns></returns>
        public async Task <DeviceListQueryResult> GetDeviceList(DeviceListQuery query)
        {
            List <dynamic> deviceList = await GetAllDevicesAsync();

            IQueryable <dynamic> filteredDevices = FilterHelper.FilterDeviceList(deviceList.AsQueryable <dynamic>(), query.Filters);

            IQueryable <dynamic> filteredAndSearchedDevices = SearchDeviceList(filteredDevices, query.SearchQuery);

            IQueryable <dynamic> sortedDevices = SortDeviceList(filteredAndSearchedDevices, query.SortColumn, query.SortOrder);

            List <dynamic> pagedDeviceList = sortedDevices.Skip(query.Skip).Take(query.Take).ToList();

            int filteredCount = filteredAndSearchedDevices.Count();

            return(new DeviceListQueryResult()
            {
                Results = pagedDeviceList,
                TotalDeviceCount = deviceList.Count,
                TotalFilteredCount = filteredCount
            });
        }
Esempio n. 11
0
        public async void DeleteAllDevices()
        {
            var             devices    = fixture.Create <DeviceListQueryResult>();
            DeviceListQuery saveObject = null;

            deviceLogic.Setup(mock => mock.GetDevices(It.IsAny <DeviceListQuery>()))
            .Callback <DeviceListQuery>(obj => saveObject = obj)
            .ReturnsAsync(devices);

            deviceLogic.Setup(mock => mock.RemoveDeviceAsync(It.IsAny <string>())).Returns(Task.FromResult(true));

            var res = await deviceApiController.DeleteAllDevices();

            Assert.Equal(saveObject.Skip, 0);
            Assert.Equal(saveObject.Take, 1000);
            Assert.Equal(saveObject.SortColumn, "DeviceID");
            res.AssertOnError();
            var data = res.ExtractContentDataAs <bool>();

            Assert.True(data);
        }
        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);
        }
Esempio n. 13
0
        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);
        }
 public async Task <DeviceListQueryResult> GetDevices(DeviceListQuery q)
 {
     return(await _deviceRegistryListRepository.GetDeviceList(q));
 }