/// <summary>
        /// Displays a dialog and a toast notification corresponding to the given beacon action.
        /// </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(
                Windows.UI.Core.CoreDispatcherPriority.Normal, async () =>
            {
                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));
                                _beaconActionDialogOperation.Cancel();
                                _beaconActionDialogOperation = null;
                            })));

                        messageDialog.Commands.Add(new UICommand("No"));

                        _beaconActionDialogOperation = messageDialog.ShowAsync();
                        break;

                    case BeaconActionType.InApp:
                        await messageDialog.ShowAsync();
                        break;
                }
            });
        }
        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();
        }
        public async Task EventHistory_FlushHistory()
        {

            SDKData.Instance.ApiKey = "540aa95ccf215718295c2c563a2090676994f09927f09a6e09a67c83be10b00c";
            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() { SupressionTime = 100, SendOnlyOnce = true, BeaconAction = beaconaction1 };
            ResolvedAction res2 = new ResolvedAction() { SupressionTime = 100, SendOnlyOnce = true, BeaconAction = beaconaction2 };
            ResolvedAction res3 = new ResolvedAction() { SupressionTime = 1, SendOnlyOnce = true, BeaconAction = beaconaction3 };

            EventHistory eventHistory = new EventHistory();

            await eventHistory.SaveBeaconEventAsync(args);
            await eventHistory.SaveExecutedResolvedActionAsync(resolvedActionEventArgs, beaconaction1);
            await eventHistory.SaveExecutedResolvedActionAsync(resolvedActionEventArgs, beaconaction3);

            await eventHistory.FlushHistoryAsync();


        }
        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
        }
 private bool Equals(BeaconAction other)
 {
     return Id == other.Id && Type == other.Type && string.Equals(Uuid, other.Uuid) && string.Equals(Subject, other.Subject) && string.Equals(Body, other.Body) &&
            string.Equals(Url, other.Url) && Equals(Payload?.ToString(), other.Payload?.ToString());
 }
        /// <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();
                });
        }
        /// <summary>
        /// Creates a beacon action instance from the given string.
        /// </summary>
        /// <param name="beaconActionAsString">The beacon action as string.</param>
        /// <returns>A newly created beacon action instance, if successful. Null in case of an error.</returns>
        public static BeaconAction FromString(string beaconActionAsString)
        {
            BeaconAction beaconAction = null;

            if (!string.IsNullOrEmpty(beaconActionAsString))
            {
                string[] fields = beaconActionAsString.Split(FieldSeparator);

                if (fields.Length >= 2)
                {
                    beaconAction = new BeaconAction();

                    for (int i = 0; i < fields.Length; ++i)
                    {
                        if (fields[i].Trim().Length > 0)
                        {
                            switch (i)
                            {
                                case 0: // Id
                                    int id = 0;

                                    try
                                    {
                                        int.TryParse(fields[i], out id);
                                    }
                                    catch (Exception)
                                    {
                                    }

                                    beaconAction.Id = id;
                                    break;
                                case 1: // Type
                                    beaconAction.SetType(fields[i]);
                                    break;
                                case 2: // Subject
                                    beaconAction.Subject = fields[i];
                                    break;
                                case 3: // Body
                                    beaconAction.Body = fields[i];
                                    break;
                                case 4: // Url
                                    beaconAction.Url = fields[i];
                                    break;
                                case 5: // Payload
                                    JsonObject payload = null;
                                    bool jsonObjectParsed = false;

                                    try
                                    {
                                        jsonObjectParsed = JsonObject.TryParse(fields[i], out payload);
                                    }
                                    catch (Exception)
                                    {
                                    }

                                    if (jsonObjectParsed)
                                    {
                                        beaconAction.Payload = payload;
                                    }

                                    break;
                            }
                        }
                    }
                }
            }

            return beaconAction;
        }
Beispiel #8
0
 private bool Equals(BeaconAction other)
 {
     return(Id == other.Id && Type == other.Type && string.Equals(Uuid, other.Uuid) && string.Equals(Subject, other.Subject) && string.Equals(Body, other.Body) &&
            string.Equals(Url, other.Url) && Equals(Payload?.ToString(), other.Payload?.ToString()));
 }
 public Task SaveHistoryAction(BeaconAction beaconAction)
 {
     throw new NotImplementedException();
 }
 public Task SaveActionForForeground(BeaconAction beaconAction)
 {
     throw new NotImplementedException();
 }
        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>
        /// 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 async void OnBeaconActionResolvedAsync(object sender, BeaconAction beaconAction)
        {
            System.Diagnostics.Debug.WriteLine("BackgroundEngine.OnBeaconActionResolvedAsync()");
            await Storage.Instance.SaveBeaconActionFromBackgroundAsync(beaconAction);
            _newActionsFromBackground = true;

            if (SDKData.Instance.ShowNotificationsOnBackground())
            {
                // Toast notifications are shown only if the app is not visible
                ToastNotification toastNotification = beaconAction.ToToastNotification();
                NotificationUtils.ShowToastNotification(toastNotification);
            }
        }