public async Task ResolveMultipleAction()
        {
            LayoutManager layoutManager = (LayoutManager)ServiceManager.LayoutManager;
            await layoutManager.VerifyLayoutAsync(true);

            SdkEngine engine = new SdkEngine(false);
            await engine.InitializeAsync();

            TaskCompletionSource <IList <BeaconAction> > action = new TaskCompletionSource <IList <BeaconAction> >();
            IList <BeaconAction> list = new List <BeaconAction>();

            engine.BeaconActionResolved += (sender, args) =>
            {
                list.Add(args);
                if (list.Count >= 3)
                {
                    action.TrySetResult(list);
                }
            };
            await
            engine.ResolveBeaconAction(new BeaconEventArgs()
            {
                Beacon = new Beacon()
                {
                    Id1 = "7367672374000000ffff0000ffff0003", Id2 = 48869, Id3 = 21321
                },
                EventType = BeaconEventType.Enter
            });

            IList <BeaconAction> result = await action.Task;

            Assert.AreEqual(4, result.Count, "Not 4 action found");
        }
        public async Task ResolveBackgroundBeaconsSingleAction()
        {
            LayoutManager layoutManager = (LayoutManager)ServiceManager.LayoutManager;
            await layoutManager.VerifyLayoutAsync(true);

            SdkEngine engine = new SdkEngine(false);
            await engine.InitializeAsync();

            BeaconAction orgAction = layoutManager.Layout.ResolvedActions.FirstOrDefault(ra => ra.BeaconAction.Uuid == "9ded63644e424d758b0218f7c70f2473").BeaconAction;

            TaskCompletionSource <BeaconAction> action = new TaskCompletionSource <BeaconAction>();

            engine.BeaconActionResolved += (sender, args) =>
            {
                action.SetResult(args);
            };
            await
            engine.ResolveBeaconAction(new BeaconEventArgs()
            {
                Beacon = new Beacon()
                {
                    Id1 = "7367672374000000ffff0000ffff0004", Id2 = 39178, Id3 = 30929
                },
                EventType = BeaconEventType.Enter
            });

            BeaconAction result = await action.Task;

            Assert.AreEqual(orgAction, result, "action not found");
        }
 /// <summary>
 /// Called, when scanner sends a beacon event. If the background task is registered,
 /// it will resolve the actions and we do nothing here.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e">The beacon event.</param>
 private async void OnBeaconEventAsync(object sender, BeaconEventArgs e)
 {
     if (!IsBackgroundTaskRegistered)
     {
         await SdkEngine.ResolveBeaconAction(e);
     }
 }
Exemple #4
0
        /// <summary>
        /// Resolves beacons, which triggered the background task.
        /// </summary>
        public async Task ResolveBeaconActionsAsync(List <Beacon> beacons, int outOfRangeDb)
        {
            Logger.Trace("ResolveBeaconActionsAsync Count: " + beacons.Count);

            Beacons = beacons;
            if (Beacons.Count > 0)
            {
                await AddBeaconsToBeaconArgsAsync(outOfRangeDb);
            }

            if (_beaconArgs.Count > 0)
            {
                // Resolve new events
                foreach (var beaconArg in _beaconArgs)
                {
                    await SdkEngine.ResolveBeaconAction(beaconArg);
                }
            }
            Finished?.Invoke(this, BackgroundWorkerType.AdvertisementWorker);
        }
        public async Task TestSilentCampaign()
        {
            ((MockApiConnection)ServiceManager.ApiConnction).LayoutFile = "mock/mock_silent_layout.json";
            ServiceManager.ReadOnlyForTests = false;
            MockStorage storage = new MockStorage();

            ServiceManager.StorageService = new StorageService()
            {
                Storage = storage
            };
            ServiceManager.ReadOnlyForTests = true;

            SdkEngine engine = new SdkEngine(false);
            await engine.InitializeAsync();

            TaskCompletionSource <bool> action = new TaskCompletionSource <bool>();

            engine.BeaconActionResolved += (sender, args) =>
            {
                action.SetResult(true);
            };
            await
            engine.ResolveBeaconAction(new BeaconEventArgs()
            {
                Beacon = new Beacon()
                {
                    Id1 = "7367672374000000ffff0000ffff4321", Id2 = 39178, Id3 = 30929
                },
                EventType = BeaconEventType.Enter
            });

            if (await Task.WhenAny(action.Task, Task.Delay(500)) == action.Task)
            {
                Assert.Fail("no action should fired");
            }
            else
            {
                Assert.AreEqual(1, storage.UndeliveredActions.Count, "Not 1 undlivered action");
                Assert.AreEqual(1, storage.UndeliveredEvents.Count, "Not 1 undlivered event");
            }
        }
        public async Task ResolveSingleActionNoResult()
        {
            LayoutManager layoutManager = (LayoutManager)ServiceManager.LayoutManager;
            await layoutManager.VerifyLayoutAsync(true);

            SdkEngine engine = new SdkEngine(false);
            await engine.InitializeAsync();

            TaskCompletionSource <IList <BeaconAction> > action = new TaskCompletionSource <IList <BeaconAction> >();
            IList <BeaconAction> list = new List <BeaconAction>();

            engine.BeaconActionResolved += (sender, args) =>
            {
                list.Add(args);
                if (list.Count >= 3)
                {
                    action.SetResult(list);
                }
            };
            await
            engine.ResolveBeaconAction(new BeaconEventArgs()
            {
                Beacon = new Beacon()
                {
                    Id1 = "7367672374000000ffff0000ffff1234", Id2 = 39178, Id3 = 30929
                },
                EventType = BeaconEventType.Enter
            });

            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
            }
        }