BackgroundEngine resolves actions from BluetoothLEAdvertisementWatcherTriggerDetails object and resolves delayed actions. This is not part of the public API. Making modifications into background tasks is not required in order to use the SDK.
Наследование: IDisposable
//        [Timeout(2000)]
        public async Task ResolveBackgroundEventSingle()
        {
            logger.Debug("ResolveBackgroundEventSingle - Start");
            LayoutManager layoutManager = (LayoutManager) ServiceManager.LayoutManager;
            await layoutManager.VerifyLayoutAsync(true);
            BeaconAction orgAction = layoutManager.Layout.ResolvedActions.FirstOrDefault(ra => ra.BeaconAction.Uuid == "9ded63644e424d758b0218f7c70f2473").BeaconAction;

            List<Beacon> list = new List<Beacon>()
            {
                new Beacon() {Id1 = "7367672374000000ffff0000ffff0004", Id2 = 39178, Id3 = 30929},
                new Beacon() {Id1 = "7367672374000000ffff0000ffff0004", Id2 = 39178, Id3 = 30929}
            };
            BackgroundEngine engine = new BackgroundEngine();
            TaskCompletionSource<BeaconAction> action = new TaskCompletionSource<BeaconAction>();
            int resolveCount = 0;
            engine.BeaconActionResolved += (sender, args) =>
            {
                resolveCount++;
                action.SetResult(args);
            };
            await engine.InitializeAsync();
            await engine.ResolveBeaconActionsAsync(list, OUT_OF_RANGE_DB);


            BeaconAction result = await action.Task;

            Assert.AreEqual(orgAction, result, "action not found");
            Assert.AreEqual(1, resolveCount, "More then onetime resolved");
            logger.Debug("ResolveBackgroundEventSingle - End");
        }
 private void OnFinished(object sender, BackgroundWorkerType e)
 {
     System.Diagnostics.Debug.WriteLine("TimedBackgroundWorker.OnFinished()");
     Deferral?.Complete();
     BackgroundEngine.Finished -= OnFinished;
     BackgroundEngine.Dispose();
 }
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            System.Diagnostics.Debug.WriteLine("TimedBackgroundWorker.Run()");
            Deferral = taskInstance.GetDeferral();

            await BackgroundEngine.InitializeAsync();

            await BackgroundEngine.ProcessDelayedActionsAsync();
        }
 private void OnFinished(object sender, BackgroundWorkerType type)
 {
     if (type == BackgroundWorkerType.AdvertisementWorker)
     {
         BackgroundEngine.ProcessDelayedActionsAsync(false).ConfigureAwait(false);
     }
     else
     {
         Deferral?.Complete();
         BackgroundEngine.Finished -= OnFinished;
         BackgroundEngine?.Dispose();
     }
 }
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            Deferral = taskInstance.GetDeferral();

            await BackgroundEngine.InitializeAsync();

            var triggerDetails = taskInstance.TriggerDetails as BluetoothLEAdvertisementWatcherTriggerDetails;

            if (triggerDetails != null)
            {
                if (triggerDetails.Error == BluetoothError.RadioNotAvailable)
                {
                    AdvertisementError?.Invoke(this, triggerDetails.Error);
                }
                else
                {
                    int outOfRangeDb = triggerDetails.SignalStrengthFilter.OutOfRangeThresholdInDBm.HasValue ? triggerDetails.SignalStrengthFilter.OutOfRangeThresholdInDBm.Value : 0;
                    await BackgroundEngine.ResolveBeaconActionsAsync(TriggerDetailsToBeacons(triggerDetails), outOfRangeDb);
                }
            }

            //setting any value to Progress will fire Progress event with UI app
            taskInstance.Progress = 1;
        }
 public AdvertisementWatcherBackgroundWorker()
 {
     BackgroundEngine = new BackgroundEngine();
     BackgroundEngine.Finished += OnFinished;
 }
        public async Task ResolveSingleActionNoResult()
        {
            logger.Debug("ResolveSingleActionNoResult - Start");
            LayoutManager layoutManager = (LayoutManager) ServiceManager.LayoutManager;
            await layoutManager.VerifyLayoutAsync(true);

            BackgroundEngine engine = new BackgroundEngine();
            TaskCompletionSource<IList<BeaconAction>> action = new TaskCompletionSource<IList<BeaconAction>>();
            IList<BeaconAction> actions = new List<BeaconAction>();
            engine.BeaconActionResolved += (sender, args) =>
            {
                actions.Add(args);
                if (actions.Count >= 3)
                {
                    action.SetResult(actions);
                }
            };
            List<Beacon> list = new List<Beacon>() {new Beacon() {Id1 = "7367672374000000ffff0000ffff1234", Id2 = 39178, Id3 = 30929}};

            if (await Task.WhenAny(action.Task, Task.Delay(500)) == action.Task)
            {
                Assert.AreEqual(0, action.Task.Result, "Not 0 action found");
            }
            else
            {
                //timeout is fine
            }
            logger.Debug("ResolveSingleActionNoResult - End");
        }
        public async Task ResolveMultipleAction()
        {
            logger.Debug("ResolveMultipleAction - Start");
            LayoutManager layoutManager = (LayoutManager) ServiceManager.LayoutManager;
            await layoutManager.VerifyLayoutAsync(true);

            BackgroundEngine engine = new BackgroundEngine();
            IList<BeaconAction> actions = new List<BeaconAction>();
            engine.BeaconActionResolved += (sender, args) =>
            {
                actions.Add(args);
            };
            List<Beacon> list = new List<Beacon>() {new Beacon() {Id1 = "7367672374000000ffff0000ffff0003", Id2 = 48869, Id3 = 21321}};

            await engine.InitializeAsync();
            await engine.ResolveBeaconActionsAsync(list, OUT_OF_RANGE_DB);


            Assert.AreEqual(4, actions.Count, "Not 4 action found");
            logger.Debug("ResolveMultipleAction - End");
        }
 public TimedBackgroundWorker()
 {
     BackgroundEngine = new BackgroundEngine();
     BackgroundEngine.Finished += OnFinished;
 }
 public AdvertisementWatcherBackgroundWorker()
 {
     BackgroundEngine           = new BackgroundEngine();
     BackgroundEngine.Finished += OnFinished;
 }
 public TimedBackgroundWorker()
 {
     BackgroundEngine           = new BackgroundEngine();
     BackgroundEngine.Finished += OnFinished;
 }