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"); }
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"); }
/// <summary> /// Initializes the SDK using the given configuration. The scanner can be used separately, but /// the resolving beacon actions cannot be done unless the SDK is initialized. /// If background task is enabled, this method check if there are updates for the /// background task filters available and updates them if so. /// </summary> public async Task InitializeAsync(SdkConfiguration configuration) { Status.IsApiKeyValid = false; _logger.Debug("InitializeAsync"); Configuration = configuration; SdkEngine.Configuration = configuration; if (!IsInitialized) { await SdkEngine.InitializeAsync(); await InitializeSettingsAsync(); Status.IsApiKeyValid = ServiceManager.LayoutManager.IsLayoutValid; Scanner.StatusChanged += OnScannerStatusChanged; Scanner.BeaconEvent += OnBeaconEventAsync; } if (SdkData.BackgroundTaskEnabled) { _logger.Debug("InitializeAsync#InitializeBackgground"); await UpdateBackgroundTaskIfNeededAsync(); } if (configuration.AutoStartScanner) { StartScanner(); } }
/// <summary> /// Initializes BackgroundEngine. /// </summary> public async Task InitializeAsync() { await SdkEngine.InitializeAsync(); AppSettings = await ServiceManager.SettingsManager.GetSettings(); //TODO verfiy if (BackgroundTaskManager.CheckIfBackgroundFilterUpdateIsRequired()) { ToastNotification toastNotification = NotificationUtils.CreateToastNotification("New beacon signature available", "Launch the application to update"); NotificationUtils.ShowToastNotification(toastNotification); } }
public async Task UpdateExitTimeoutTest() { SdkEngine engine = new SdkEngine(true); await engine.InitializeAsync(); AppSettings appSettings = engine.AppSettings; Assert.AreEqual((ulong)123, appSettings.BeaconExitTimeout); Assert.AreEqual((ulong)123, engine.Resolver.BeaconExitTimeout); ((MockApiConnection)ServiceManager.ApiConnction).MockSettings = "{\"revision\":0,\"settings\":{\"scanner.backgroundWaitTime\":120000, \"scanner.exitTimeoutMillis\":123000, \"network.historyUploadInterval\":321}}"; ((SettingsManager)ServiceManager.SettingsManager).OnTimerTick(null); appSettings = engine.AppSettings; Assert.AreEqual((ulong)123000, appSettings.BeaconExitTimeout); Assert.AreEqual((ulong)123000, engine.Resolver.BeaconExitTimeout); }
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 } }