Exemple #1
0
        /// <summary>
        /// Handles device property changes
        /// </summary>
        void HandleDeviceUpdated(object sender, DeviceUpdatedEventArgs e)
        {
            var listDevice = Devices.FirstOrDefault(p => p.UserDeviceId == e.Device.UserDeviceId);

            if (listDevice == SelectedDevice)
            {
                foreach (var prop in e.Properties)
                {
                    var listItemProp = SelectedDeviceProperties.FirstOrDefault(p => p.Name == prop.Name);
                    if (listItemProp != null)
                    {
                        // Update existing item
                        listItemProp.Name  = prop.Name;
                        listItemProp.Value = prop.Value;
                        MessagingCenter.Send(this, PropertyUpdatedMessage, prop);
                    }
                    else
                    {
                        // Add new property
                        SelectedDeviceProperties.Add(prop);
                    }
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Loads device data/properties
        /// </summary>
        async Task LoadDevicePropertiesAsync(DeviceModel device)
        {
            if (device == null)
            {
                SelectedDeviceProperties.Clear();
                IsLoadingDeviceProperties = false;
                IsDevicePropertiesVisible = !IsLoadingDeviceProperties;
                return;
            }

            IsLoadingDeviceProperties = true;
            IsDevicePropertiesVisible = !IsLoadingDeviceProperties;

            bool lightInterface = false;

            try
            {
                // find device in list and update
                var props = await DeviceDriveManager.Current.GetDevicePropertiesAsync(device);

                if (props != null)
                {
                    if (props.Count() != SelectedDeviceProperties.Count())
                    {
                        SelectedDeviceProperties.Clear();
                        foreach (var prop in props)
                        {
                            if (prop.InterfaceName.Equals("com.devicedrive.light"))
                            {
                                lightInterface = true;
                            }
                            if (prop.Name.ToLower().Equals("switch"))
                            {
                                LightBulbSwitch = prop.Value.Equals("1");
                            }
                            if (prop.Name.ToLower().Equals("intensity"))
                            {
                                LightBulbIntensity = (int)Math.Round(Double.Parse(prop.Value, CultureInfo.InvariantCulture));
                            }
                            SelectedDeviceProperties.Add(prop);
                        }
                    }
                    else
                    {
                        foreach (var prop in props)
                        {
                            System.Diagnostics.Debug.WriteLine("Updating " + prop.Name + " = " + prop.Value);
                            var listItemProp = SelectedDeviceProperties.FirstOrDefault(p => p.Name == prop.Name);
                            if (listItemProp != null)
                            {
                                listItemProp.Name  = prop.Name;
                                listItemProp.Value = prop.Value;
                                if (prop.Name.ToLower().Equals("switch"))
                                {
                                    LightBulbSwitch = prop.Value.Equals("1");
                                }
                                if (prop.Name.ToLower().Equals("intensity"))
                                {
                                    LightBulbIntensity = (int)Math.Round(Double.Parse(prop.Value, CultureInfo.InvariantCulture));
                                }

                                MessagingCenter.Send(this, PropertyUpdatedMessage, prop);
                            }
                        }
                    }
                }
            }
            finally
            {
                IsLoadingDeviceProperties = false;
                IsDevicePropertiesVisible = !IsLoadingDeviceProperties;
                IsLightBulbVisible        = lightInterface;
            }
        }