Пример #1
0
        public async void Run(Windows.ApplicationModel.Background.IBackgroundTaskInstance taskInstance)
        {
            BackgroundTaskDeferral deferral = taskInstance.GetDeferral();

            try
            {
                DeviceConnectionChangeTriggerDetails details = (DeviceConnectionChangeTriggerDetails)taskInstance.TriggerDetails;
                BluetoothLEDevice bleDevice = await BluetoothLEDevice.FromIdAsync(details.DeviceId);

                Racer device = new Racer(bleDevice);

                if (bleDevice.ConnectionStatus == BluetoothConnectionStatus.Connected)
                {
                    if (device.AlertOnDevice && device.HasLinkLossService)
                    {
                        await device.SetAlertLevelCharacteristic();
                    }
                }
                else
                {
                    if (device.AlertOnPhone)
                    {
                        XmlDocument xml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText01);
                        xml.SelectSingleNode("/toast/visual/binding/text").InnerText = string.Format("Device {0} is out of range.", device.Name);
                        ToastNotification toast    = new ToastNotification(xml);
                        ToastNotifier     notifier = ToastNotificationManager.CreateToastNotifier();
                        notifier.Show(toast);
                    }
                }
            }
            finally
            {
                deferral.Complete();
            }
        }
Пример #2
0
        public async void Run(Windows.ApplicationModel.Background.IBackgroundTaskInstance taskInstance)
        {
            BackgroundTaskDeferral deferral = taskInstance.GetDeferral();
            try
            {
                DeviceConnectionChangeTriggerDetails details = (DeviceConnectionChangeTriggerDetails)taskInstance.TriggerDetails;
                BluetoothLEDevice bleDevice = await BluetoothLEDevice.FromIdAsync(details.DeviceId);
                Racer device = new Racer(bleDevice);

                if (bleDevice.ConnectionStatus == BluetoothConnectionStatus.Connected)
                {
                    if (device.AlertOnDevice && device.HasLinkLossService)
                    {
                        await device.SetAlertLevelCharacteristic();
                    }
                }
                else
                {
                    if (device.AlertOnPhone)
                    {
                        XmlDocument xml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText01);
                        xml.SelectSingleNode("/toast/visual/binding/text").InnerText = string.Format("Device {0} is out of range.", device.Name);
                        ToastNotification toast = new ToastNotification(xml);
                        ToastNotifier notifier = ToastNotificationManager.CreateToastNotifier();
                        notifier.Show(toast);
                    }
                }
            }
            finally
            {
                deferral.Complete();
            }
        }