private async Task <BackgroundTaskRegistration> RegisterDeviceServiceAsBackgroundTask(GattDeviceService deviceService)
        {
            var           deviceAddress = ConvertingTools.GetBLEMacAddress(deviceService.Device.BluetoothAddress);
            StringBuilder name          = new StringBuilder(ToolboxIdentifications.PageId.PROXIMITY + ",");

            name.Append(deviceService.DeviceId);
            KeyValuePair <GattDeviceService, BackgroundTaskRegistration> task;

            if (this.linkLossServiceTaskRegistrations.TryGetValue(name.ToString(), out task))
            {
                task.Value.Unregister(true);
                linkLossServiceTaskRegistrations.Remove(name.ToString());
            }
            DeviceConnectionChangeTrigger trigger = await DeviceConnectionChangeTrigger.FromIdAsync(deviceService.DeviceId);

            BackgroundTaskBuilder builder = new BackgroundTaskBuilder();

            trigger.MaintainConnection = true;
            builder.Name           = name.ToString();
            builder.TaskEntryPoint = ENTRY_POINT;
            builder.SetTrigger(trigger);
            var newTask = builder.Register();

            linkLossServiceTaskRegistrations.Add(name.ToString(), new KeyValuePair <GattDeviceService, BackgroundTaskRegistration>(deviceService, newTask));
            return(newTask);
        }
예제 #2
0
        public async void RegisterDeviceConnectionBackgroundTask(string deviceId)
        {
            foreach (var task in BackgroundTaskRegistration.AllTasks)
            {
                if (task.Value.Name == nameof(DeviceConnectionBackgroundTask))
                {
                    task.Value.Unregister(false);
                }
            }
            var builder = new BackgroundTaskBuilder
            {
                Name           = nameof(DeviceConnectionBackgroundTask),
                TaskEntryPoint = typeof(DeviceConnectionBackgroundTask).FullName
            };
            var trigger = await DeviceConnectionChangeTrigger.FromIdAsync(deviceId);

            trigger.MaintainConnection = true;
            builder.SetTrigger(trigger);
            BackgroundTaskRegistration t = builder.Register();
            await client.LogAsync($"Successfully registered decive connection changed task");
        }