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();


        }
Beispiel #3
0
        private async void OnBeaconActionResolvedAsync(object sender, ResolvedActionsEventArgs e)
        {
            if (e == null || e.ResolvedActions == null || e.ResolvedActions.Count == 0)
            {
                return;
            }
            Logger.Debug("SDKEngine: OnBeaconActionResolvedAsync " + e.RequestId + " BeaconEventType:" + e.BeaconEventType);
            foreach (ResolvedAction action in e.ResolvedActions)
            {
                try
                {
                    if (action.Delay > 0 && !action.ReportImmediately)
                    {
                        Logger.Debug("SDKEngine: OnBeaconActionResolvedAsync " + e.RequestId + " delay");
                        // Delay action execution
                        DateTimeOffset dueTime = DateTimeOffset.Now.AddSeconds((int)action.Delay);

                        await ServiceManager.StorageService.SaveDelayedAction(action, dueTime, e.BeaconPid, action.EventTypeDetectedByDevice, e.Location);

                        if (_appIsOnForeground && (_processDelayedActionsTimer == null || _nextTimeToProcessDelayedActions > dueTime))
                        {
                            if (_nextTimeToProcessDelayedActions > dueTime)
                            {
                                _nextTimeToProcessDelayedActions = dueTime;
                            }

                            ResetProcessDelayedActionsTimer(dueTime);
                        }
                    }
                    else
                    {
                        Logger.Debug("SDKEngine: OnBeaconActionResolvedAsync/ExecuteActionAsync " + e.RequestId + " -> Beacon Pid " + e.BeaconPid);
                        // Execute action immediately
                        await ExecuteActionAsync(action, e.BeaconPid, e.BeaconEventType, e.Location);
                    }
                }
                catch (Exception ex)
                {
                    Logger.Error("Error while handling resolved action", ex);
                }
            }
        }
Beispiel #4
0
        /// <summary>
        /// Handles a completed (or failed) request.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnRequestResult(object sender, RequestResultState e)
        {
            Request request = sender as Request;

            if (request != null)
            {
                request.Result -= OnRequestResult;

                if (e == RequestResultState.Success)
                {
                    System.Diagnostics.Debug.WriteLine("Resolver.OnRequestResult(): Request with ID " + request.RequestId + " was successful");

                    if (ActionsResolved != null)
                    {
                        ResolvedActionsEventArgs eventArgs = new ResolvedActionsEventArgs();
                        eventArgs.ResolvedActions = request.ResolvedActions;
                        eventArgs.RequestID = request.RequestId;
                        eventArgs.BeaconEventType = request.BeaconEventArgs.EventType;
                        
                        if (request.BeaconEventArgs != null && request.BeaconEventArgs.Beacon != null)
                        {
                            eventArgs.BeaconPid = request.BeaconEventArgs.Beacon.Pid;
                        }

                        ActionsResolved(this, eventArgs);
                    }
                }
                else if (e == RequestResultState.Failed)
                {
                    System.Diagnostics.Debug.WriteLine("Resolver.OnRequestResult(): Request with ID " + request.RequestId + " failed");

                    if (FailedToResolveActions != null)
                    {
                        FailedToResolveActions(this, request.ErrorMessage);
                    }
                }

                request = null;        
            }
        }
        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
        }
Beispiel #6
0
 private void Res_ActionResolved(object sender, ResolvedActionsEventArgs e)
 {
     _e = e;
     _manualEvent.Set();
 }
Beispiel #7
0
        private async void OnBeaconActionResolvedAsync(object sender, ResolvedActionsEventArgs e)
        {
            if (e != null && e.ResolvedActions.Count > 0 && BeaconActionResolved != null)
            {
                foreach (ResolvedAction action in e.ResolvedActions)
                {
                    if (action.Delay > 0 && action.ReportImmediately == false)
                    {
                        // Delay action execution
                        DateTimeOffset dueTime = DateTimeOffset.Now.AddSeconds((int)action.Delay);

                        await Storage.Instance.SaveDelayedActionAsync(
                            action, dueTime, e.BeaconPid, action.EventTypeDetectedByDevice);

                        if (_appIsOnForeground
                            && (_processDelayedActionsTimer == null || _nextTimeToProcessDelayedActions > dueTime))
                        {
                            if (_nextTimeToProcessDelayedActions > dueTime)
                            {
                                _nextTimeToProcessDelayedActions = dueTime;
                            }

                            ResetProcessDelayedActionsTimer(dueTime);
                        }
                    }
                    else
                    {
                        // Execute action immediately
                        await ExecuteActionAsync(action, e.BeaconPid, e.BeaconEventType);
                    }
                }
            }
            UnresolvedActionCount--;
        }
 /// <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 async void OnBeaconActionResolvedAsync(object sender, ResolvedActionsEventArgs e)
        {
            if (e == null || e.ResolvedActions == null || e.ResolvedActions.Count == 0)
            {
                return;
            }
            Logger.Debug("SDKEngine: OnBeaconActionResolvedAsync " + e.RequestId + " BeaconEventType:" + e.BeaconEventType);
            foreach (ResolvedAction action in e.ResolvedActions)
            {
                try
                {
                    if (action.Delay > 0 && !action.ReportImmediately)
                    {
                        Logger.Debug("SDKEngine: OnBeaconActionResolvedAsync " + e.RequestId + " delay");
                        // Delay action execution
                        DateTimeOffset dueTime = DateTimeOffset.Now.AddSeconds((int) action.Delay);

                        await ServiceManager.StorageService.SaveDelayedAction(action, dueTime, e.BeaconPid, action.EventTypeDetectedByDevice, e.Location);

                        if (_appIsOnForeground && (_processDelayedActionsTimer == null || _nextTimeToProcessDelayedActions > dueTime))
                        {
                            if (_nextTimeToProcessDelayedActions > dueTime)
                            {
                                _nextTimeToProcessDelayedActions = dueTime;
                            }

                            ResetProcessDelayedActionsTimer(dueTime);
                        }
                    }
                    else
                    {
                        Logger.Debug("SDKEngine: OnBeaconActionResolvedAsync/ExecuteActionAsync " + e.RequestId + " -> Beacon Pid " + e.BeaconPid);
                        // Execute action immediately
                        await ExecuteActionAsync(action, e.BeaconPid, e.BeaconEventType, e.Location);
                    }
                }
                catch (Exception ex)
                {
                    Logger.Error("Error while handling resolved action", ex);
                }
            }
        }