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"); }
// [Timeout(10000)] public async Task ResolveBackgroundEvent() { logger.Debug("ResolveBackgroundEvent - 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 } }; BackgroundEngine engine = new BackgroundEngine(); TaskCompletionSource <BeaconAction> action = new TaskCompletionSource <BeaconAction>(); engine.BeaconActionResolved += (sender, args) => { 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"); logger.Debug("ResolveBackgroundEvent - End"); }
/// <summary> /// Handles incoming beacon actions, when the application is running. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void OnBeaconActionResolvedAsync(object sender, BeaconAction e) { await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync( CoreDispatcherPriority.Normal, async() => { string logEntryMessage = "Beacon action resolved:" + "\n- ID: " + e.Id + "\n- " + (string.IsNullOrEmpty(e.Subject) ? "(No subject)" : "Subject: " + e.Subject) + "\n- " + (string.IsNullOrEmpty(e.Body) ? "(No body)" : "Body: " + e.Body) + "\n- " + (string.IsNullOrEmpty(e.Url) ? "(No URL)" : "URL: " + e.Url); AddLogEntry(logEntryMessage); MessageDialog messageDialog = e.ToMessageDialog(); switch (e.Type) { case BeaconActionType.UrlMessage: case BeaconActionType.VisitWebsite: messageDialog.Commands.Add(new UICommand("Yes", new UICommandInvokedHandler(async(command) => { await Windows.System.Launcher.LaunchUriAsync(new Uri(e.Url)); }))); messageDialog.Commands.Add(new UICommand("No")); break; case BeaconActionType.InApp: break; } await messageDialog.ShowAsync(); }); }
public object Convert(object value, Type targetType, object parameter, string language) { BeaconAction ra = value as BeaconAction; if (ra != null) { if (ra.Payload != null && ra.Payload.ContainsKey("color")) { string colorName = ra.Payload.GetNamedString("color")?.ToLowerInvariant(); switch (colorName) { case "green": { return(new SolidColorBrush(Colors.LightGreen)); } case "red": { return(new SolidColorBrush(Colors.Red)); } case "yellow": { return(new SolidColorBrush(Colors.Yellow)); } } } } return(null); }
public void ReplaceSwitchBeaconActionRequest(BeaconAction newNewBeaconAction) { var index = GameComponentsLookup.SwitchBeaconActionRequest; var component = CreateComponent <SwitchBeaconActionRequest>(index); component.NewBeaconAction = newNewBeaconAction; ReplaceComponent(index, component); }
public async void ActionResolved(BeaconAction beaconAction) { await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { string s = string.Format("Event received: {0}\nType: {3}\nEvent subject: {1}\nPayload: {2}", DateTime.Now, beaconAction.Subject, beaconAction.PayloadString, beaconAction.Type); ResolvedActions.Insert(0, s); }); }
public void ReplaceBeaconAction(BeaconAction newValue) { var index = GameComponentsLookup.BeaconAction; var component = CreateComponent <BeaconActionComponent>(index); component.Value = newValue; ReplaceComponent(index, component); }
public void ReplaceBeacon(BeaconAction newAction, float newRange) { var index = GameComponentsLookup.Beacon; var component = CreateComponent <BeaconComponent>(index); component.Action = newAction; component.Range = newRange; ReplaceComponent(index, component); }
private async void OnBeaconActionResolved(object sender, BeaconAction e) { Logger.Debug("Beacon action resolved" + e.Body + ", " + e.Payload); await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => Model.ActionResolved(e)); if (Model.AreActionsEnabled) { NotificationUtils.ShowToastNotification(NotificationUtils.CreateToastNotification(e)); } }
public static BeaconAction BeaconActionFromString(string s) { BeaconAction action = JsonConvert.DeserializeObject <BeaconAction>(s); if (!string.IsNullOrEmpty(action?.PayloadString)) { action.Payload = JsonObject.Parse(action.PayloadString); } return(action); }
public async Task BeaconMultipleEnteredOneFired() { MockBeaconScanner scanner = (MockBeaconScanner)ServiceManager.BeaconScanner; SDKManager sdkManager = SDKManager.Instance(); sdkManager.ScannerStatusChanged += (sender, status) => { }; TaskCompletionSource <BeaconAction> actionResolved = new TaskCompletionSource <BeaconAction>(); List <BeaconAction> actions = new List <BeaconAction>(); sdkManager.BeaconActionResolved += (sender, action) => { actions.Add(action); actionResolved.SetResult(action); }; await sdkManager.InitializeAsync(new SdkConfiguration() { ApiKey = ApiKey, ManufacturerId = ManufacturerId, BeaconCode = BeaconCode }); // Listening to the following events is not necessary, but provides interesting data for our log sdkManager.Scanner.BeaconEvent += (sender, args) => { }; sdkManager.FailedToResolveBeaconAction += (sender, s) => { }; scanner.FireBeaconEvent(new Beacon() { Id1 = "7367672374000000ffff0000ffff0008", Id2 = 23430, Id3 = 28018 }, BeaconEventType.Enter); BeaconAction action1 = await actionResolved.Task; actionResolved = new TaskCompletionSource <BeaconAction>(); Assert.AreEqual("4224871362624826b510141da0d4fc65d", action1.Uuid, "Wrong id in action"); Assert.AreEqual("payload://is.awesome", action1.Url, "Wrong url in action"); Assert.AreEqual(string.Empty, action1.Subject, "beacon 8 - Different action subject"); Assert.AreEqual(string.Empty, action1.Body, "beacon 8 - Different action body"); Assert.AreEqual("payload://is.awesome", action1.Url, "beacon 8 - wrong url is set"); Assert.IsNotNull(action1.Payload, "beacon 8 - Payload is null"); Assert.AreEqual(JsonObject.Parse("{\"payload\":\"is\",\"awesome\":true}").ToString(), action1.Payload.ToString()); scanner.FireBeaconEvent(new Beacon() { Id1 = "7367672374000000ffff0000ffff0008", Id2 = 23430, Id3 = 28018 }, BeaconEventType.Enter); Debug.WriteLine("Waiting"); await Task.Delay(2000); Debug.WriteLine("Waiting done"); Assert.AreEqual(1, actions.Count, "Action missing or to many"); }
public async Task EventHistory_FlushHistory() { var beacon = new Beacon(); beacon.Id1 = "7367672374000000ffff0000ffff0007"; beacon.Id2 = 8008; beacon.Id3 = 5; beacon.Timestamp = DateTimeOffset.Now; var args = new BeaconEventArgs(); args.Beacon = beacon; args.EventType = BeaconEventType.Exit; var resolvedActionEventArgs = new ResolvedActionsEventArgs() { BeaconPid = beacon.Pid, BeaconEventType = BeaconEventType.Enter }; BeaconAction beaconaction1 = new BeaconAction() { Body = "body", Url = "http://www.com", Uuid = "1223" }; BeaconAction beaconaction2 = new BeaconAction() { Body = "body", Url = "http://www.com", Uuid = "5678" }; BeaconAction beaconaction3 = new BeaconAction() { Body = "body", Url = "http://www.com", Uuid = "9678" }; ResolvedAction res1 = new ResolvedAction() { SuppressionTime = 100, SendOnlyOnce = true, BeaconAction = beaconaction1 }; ResolvedAction res2 = new ResolvedAction() { SuppressionTime = 100, SendOnlyOnce = true, BeaconAction = beaconaction2 }; ResolvedAction res3 = new ResolvedAction() { SuppressionTime = 1, SendOnlyOnce = true, BeaconAction = beaconaction3 }; EventHistory eventHistory = new EventHistory(); await eventHistory.SaveBeaconEventAsync(args, null); await eventHistory.SaveExecutedResolvedActionAsync(resolvedActionEventArgs, beaconaction1); await eventHistory.SaveExecutedResolvedActionAsync(resolvedActionEventArgs, beaconaction3); await eventHistory.FlushHistoryAsync(); }
private static BeaconSettings GetBeaconSettings(BeaconAction action) { try { return(Contexts.sharedInstance.game.settingsEntity.beaconsSettings.Map[action]); } catch (Exception exception) { Debug.LogError(string.Format("Could not find proper settings for beacon action {0}: {1}", action, exception.Message)); } return(null); }
protected override void Execute(List <GameEntity> requestEntities) { foreach (var requestEntity in requestEntities) { BeaconAction newAction = requestEntity.switchBeaconActionRequest.NewBeaconAction; gameContext.gameStateEntity.ReplaceBeaconAction(newAction); gameContext.gameStateEntity.ReplaceBeaconRange( BeaconService.GetDefaultRangeForAction(newAction) ); gameContext.gameStateEntity.ReplaceBeaconCost( BeaconService.GetDefaultCostForAction(newAction) ); } }
public override int GetHashCode() { unchecked { var hashCode = _beaconPids != null?_beaconPids.GetHashCode() : 0; hashCode = (hashCode * 397) ^ (BeaconAction != null ? BeaconAction.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (int)EventTypeDetectedByDevice; hashCode = (hashCode * 397) ^ Delay.GetHashCode(); hashCode = (hashCode * 397) ^ SendOnlyOnce.GetHashCode(); hashCode = (hashCode * 397) ^ SuppressionTime; hashCode = (hashCode * 397) ^ ReportImmediately.GetHashCode(); hashCode = (hashCode * 397) ^ (Timeframes != null ? Timeframes.GetHashCode() : 0); return(hashCode); } }
public void TestBeaconActionFromString() { string s = "{\"Id\":1,\"Type\":3,\"eid\":\"uuid\",\"Subject\":\"Subject\",\"Body\":\"body\",\"Url\":\"http://sensorberg.com\",\"PayloadString\":\"{\\\"pay\\\":\\\"load\\\"}\"}"; BeaconAction beaconAction = new BeaconAction(); beaconAction.Body = "body"; beaconAction.Id = 1; beaconAction.Payload = JsonObject.Parse("{\"pay\":\"load\"}"); beaconAction.Subject = "Subject"; beaconAction.Type = BeaconActionType.InApp; beaconAction.Url = "http://sensorberg.com"; beaconAction.Uuid = "uuid"; BeaconAction action = FileStorageHelper.BeaconActionFromString(s); Assert.AreEqual(beaconAction, action); }
/// <summary> /// Creates a toast notification instance based on the data of the given beacon action. /// </summary> /// <param name="beaconAction"></param> /// <returns>A newly created toast notification.</returns> public static ToastNotification CreateToastNotification(BeaconAction beaconAction) { XmlDocument toastTemplate = CreateToastTemplate(beaconAction.Type, beaconAction.Subject, beaconAction.Body, beaconAction.Url); XmlAttribute urlAttribute = toastTemplate.CreateAttribute(KeyLaunch); string beaconActionAsString = beaconAction.ToString(); urlAttribute.Value = beaconActionAsString; XmlNodeList toastElementList = toastTemplate.GetElementsByTagName(KeyToast); XmlElement toastElement = toastElementList[0] as XmlElement; if (toastElement != null) { toastElement.SetAttribute(KeyLaunch, beaconActionAsString); } return new ToastNotification(toastTemplate); }
/// <summary> /// Creates a toast notification instance based on the data of the given beacon action. /// </summary> /// <returns>A newly created toast notification.</returns> public static ToastNotification CreateToastNotification(BeaconAction beaconAction) { XmlDocument toastTemplate = CreateToastTemplate(beaconAction.Type, beaconAction.Subject, beaconAction.Body, beaconAction.Url); XmlAttribute urlAttribute = toastTemplate.CreateAttribute(KeyLaunch); string beaconActionAsString = beaconAction.ToString(); urlAttribute.Value = beaconActionAsString; XmlNodeList toastElementList = toastTemplate.GetElementsByTagName(KeyToast); XmlElement toastElement = toastElementList[0] as XmlElement; if (toastElement != null) { toastElement.SetAttribute(KeyLaunch, beaconActionAsString); } return(new ToastNotification(toastTemplate)); }
public Task SaveHistoryAction(BeaconAction beaconAction) { throw new NotImplementedException(); }
/// <summary> /// Stores a resolved and executed action to the database. /// </summary> /// <param name="eventArgs"></param> /// <param name="beaconAction"></param> public IAsyncAction SaveExecutedResolvedActionAsync(ResolvedActionsEventArgs eventArgs, BeaconAction beaconAction) { return _storage.SaveHistoryActionAsync( beaconAction.Uuid, eventArgs.BeaconPid, DateTime.Now, (int)eventArgs.BeaconEventType).AsAsyncAction(); }
private bool Equals(ResolvedAction other) { return((!_beaconPids?.Except(other._beaconPids).GetEnumerator().MoveNext()).Value && Equals(BeaconAction.ToString(), other.BeaconAction.ToString()) && EventTypeDetectedByDevice == other.EventTypeDetectedByDevice && Delay == other.Delay && SendOnlyOnce == other.SendOnlyOnce && SuppressionTime == other.SuppressionTime && ReportImmediately == other.ReportImmediately && (!Timeframes?.Except(other.Timeframes).GetEnumerator().MoveNext()).Value); }
public static string BeaconActionToString(BeaconAction action) { return(JsonConvert.SerializeObject(action)); }
/// <summary> /// Handles BeaconActions that are resolved in the SDKEngine. /// All resolved actions are stored into local database. And the UI app will show actions to the user. /// When the UI app is not running, toast notification is shown for the user. /// </summary> private void OnBeaconActionResolvedAsync(object sender, BeaconAction beaconAction) { Logger.Trace("BackgroundEngine.OnBeaconActionResolvedAsync()"); }
public async Task EventHistory_ShouldSupress() { var beacon = new Beacon(); beacon.Id1 = "7367672374000000ffff0000ffff0007"; beacon.Id2 = 8008; beacon.Id3 = 5; beacon.Timestamp = DateTimeOffset.Now; var args = new BeaconEventArgs(); args.Beacon = beacon; args.EventType = BeaconEventType.Exit; var resolvedActionEventArgs = new ResolvedActionsEventArgs() { BeaconPid = beacon.Pid, BeaconEventType = BeaconEventType.Enter }; BeaconAction beaconaction1 = new BeaconAction() { Body = "body", Url = "http://www.com", Uuid = "1223" }; BeaconAction beaconaction2 = new BeaconAction() { Body = "body", Url = "http://www.com", Uuid = "5678" }; BeaconAction beaconaction3 = new BeaconAction() { Body = "body", Url = "http://www.com", Uuid = "9678" }; ResolvedAction res1 = new ResolvedAction() { SuppressionTime = 100, SendOnlyOnce = true, BeaconAction = beaconaction1 }; ResolvedAction res2 = new ResolvedAction() { SuppressionTime = 100, SendOnlyOnce = true, BeaconAction = beaconaction2 }; ResolvedAction res3 = new ResolvedAction() { SuppressionTime = 1, SendOnlyOnce = true, BeaconAction = beaconaction3 }; EventHistory eventHistory = new EventHistory(); await eventHistory.SaveBeaconEventAsync(args, null); await eventHistory.SaveExecutedResolvedActionAsync(resolvedActionEventArgs, beaconaction1); await eventHistory.SaveExecutedResolvedActionAsync(resolvedActionEventArgs, beaconaction3); eventHistory.ShouldSupressAsync(res1); eventHistory.ShouldSupressAsync(res3); await Task.Delay(2000); bool shouldSupress1 = eventHistory.ShouldSupressAsync(res1); bool shouldSupress2 = eventHistory.ShouldSupressAsync(res2); bool shouldSupress3 = eventHistory.ShouldSupressAsync(res3); Assert.IsTrue(shouldSupress1); Assert.IsFalse(shouldSupress2); Assert.IsFalse(shouldSupress3); //Supression time should be over }
public static float GetDefaultRangeForAction(BeaconAction action) { return(GetBeaconSettings(action).Range); }
public Task SaveActionForForeground(BeaconAction beaconAction) { throw new NotImplementedException(); }
public static string BeaconActionToString(BeaconAction action) { return JsonConvert.SerializeObject(action); }
public async Task SaveBeaconActionFromBackgroundAsync(BeaconAction action) { var beaconString = ActionFactory.Serialize(action); var payload = ""; if (action.Payload != null) { payload = action.Payload.ToString(); } DBBeaconActionFromBackground dbAction = new DBBeaconActionFromBackground() { BeaconAction = beaconString,Payload = payload }; await _db.InsertAsync(dbAction); }
/// <summary> /// For convenience. /// </summary> public async Task SaveExecutedResolvedActionAsync(BeaconAction beaconAction, string beaconPid, BeaconEventType beaconEventType, string location) { await ServiceManager.StorageService.SaveHistoryAction(beaconAction.Uuid, beaconPid, DateTime.Now, beaconEventType, location); }
/// <summary> /// Stores a resolved and executed action to the database. /// </summary> public async Task SaveExecutedResolvedActionAsync(ResolvedActionsEventArgs eventArgs, BeaconAction beaconAction) { await ServiceManager.StorageService.SaveHistoryAction(beaconAction.Uuid, eventArgs.BeaconPid, DateTime.Now, eventArgs.BeaconEventType, eventArgs.Location); }
private void SetDefaultsToGameSettings() { BeaconAction currentBeaconAction = gameContext.settingsEntity.globalSettings.Value.DefaultBeaconAction; RequestsService.CreateRequestEntity().AddSwitchBeaconActionRequest(currentBeaconAction); }
public static float GetDefaultCostForAction(BeaconAction action) { return(GetBeaconSettings(action).Cost); }
/// <summary> /// For convenience. /// </summary> /// <param name="beaconAction"></param> /// <param name="beaconPid"></param> /// <param name="beaconActionType"></param> /// <returns></returns> public IAsyncAction SaveExecutedResolvedActionAsync(BeaconAction beaconAction, string beaconPid, BeaconEventType beaconEventType) { return _storage.SaveHistoryActionAsync( beaconAction.Uuid, beaconPid, DateTime.Now, (int)beaconEventType).AsAsyncAction(); }