コード例 #1
0
        public async Task <HttpResponseMessage> GetDevicesByFilterAsync([FromUri] string filterName, [FromUri] string jobId = null)
        {
            // todo: generate some value
            var result = new DeviceListFilterResult();

            result.TotalDeviceCount   = 10;
            result.TotalFilteredCount = 1;

            var sampleTwin = new Twin()
            {
                DeviceId   = "deviceID1",
                Properties = new TwinProperties()
                {
                    Desired = new TwinCollection()
                    {
                    },
                    Reported = new TwinCollection()
                    {
                    }
                },
                Tags = new TwinCollection()
            };

            result.Results.Add(new DeviceModel()
            {
                Twin = sampleTwin, IsSimulatedDevice = true
            });

            return(await GetServiceResponseAsync <DeviceListFilterResult>(async() => (await Task.FromResult(result))));
        }
コード例 #2
0
        public async Task <HttpResponseMessage> DeleteAllDevices()
        {
            return(await GetServiceResponseAsync(async() =>
            {
                // note that you could also hardcode a filter to delete a subset of devices
                var filter = new DeviceListFilter()
                {
                    Skip = 0,
                    Take = 1000,
                    SortColumn = "twin.deviceId",
                };

                DeviceListFilterResult devices = await _deviceLogic.GetDevices(filter);

                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;
            }));
        }
コード例 #3
0
        public async Task <ActionResult> Index()
        {
            var model   = new DashboardModel();
            var clauses = new List <Infrastructure.Models.Clause>
            {
                new Clause()
                {
                    ColumnName  = "tags.HubEnabledState",
                    ClauseType  = ClauseType.EQ,
                    ClauseValue = "Running"
                }
            };


            var query = new DeviceListFilter()
            {
                Skip       = 0,
                Take       = MaxDevicesToDisplayOnDashboard,
                SortColumn = "twin.deviceId",
                Clauses    = clauses
            };

            DeviceListFilterResult filterResult = await _deviceLogic.GetDevices(query);

            if ((filterResult != null) && (filterResult.Results != null))
            {
                foreach (DeviceModel devInfo in filterResult.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;

            AddDefaultCultureIntoCookie();

            return(View(model));
        }
コード例 #4
0
        public async Task <HttpResponseMessage> GetDeviceLocationData()
        {
            return(await GetServiceResponseAsync <DeviceListLocationsModel>(async() =>
            {
                var filter = new DeviceListFilter()
                {
                    Skip = 0,
                    Take = MAX_DEVICES_TO_DISPLAY_ON_DASHBOARD,
                    SortColumn = "twin.deviceId"
                };

                DeviceListFilterResult filterResult = await _deviceLogic.GetDevices(filter);
                DeviceListLocationsModel dataModel = _deviceLogic.ExtractLocationsData(filterResult.Results);

                return dataModel;
            }, false));
        }
コード例 #5
0
        private async Task <List <DeviceModel> > LoadAllDevicesAsync()
        {
            var filter = new DeviceListFilter()
            {
                Skip       = 0,
                Take       = MAX_DEVICES_TO_DISPLAY_ON_DASHBOARD,
                SortColumn = "twin.deviceId"
            };

            string deviceId;
            var    devices = new List <DeviceModel>();
            DeviceListFilterResult filterResult = await _deviceLogic.GetDevices(filter);


            if ((filterResult != null) && (filterResult.Results != null))
            {
                bool?            enabledState;
                DeviceProperties props;
                foreach (var devInfo in filterResult.Results)
                {
                    try
                    {
                        deviceId = devInfo.DeviceProperties.DeviceID;

                        props        = devInfo.DeviceProperties;
                        enabledState = props.HubEnabledState;
                    }
                    catch (NullReferenceException)
                    {
                        continue;
                    }

                    if (!string.IsNullOrWhiteSpace(deviceId))
                    {
                        devices.Add(devInfo);
                    }
                }
            }

            return(devices);
        }