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


        }
 /// <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);
     }
 }
 /// <summary>
 /// Creates and schedules an execution of a request for the given beacon event.
 /// </summary>
 /// <param name="beaconEventArgs">The beacon event details.</param>
 /// <returns>The request ID.</returns>
 public int CreateRequest(BeaconEventArgs beaconEventArgs)
 {
     int requestId = SDKData.Instance.NextId();
     Request request = new Request(beaconEventArgs, requestId);
     request.Result += OnRequestResult;
     _requestQueue.Add(request);
     return requestId;
 }
        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 async void OnBeaconEventAsync(object sender, BeaconEventArgs eventArgs)
		{
			await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
			{
				Beacon beacon = eventArgs.Beacon;

				if (eventArgs.EventType != BeaconEventType.None)
				{
					System.Diagnostics.Debug.WriteLine("MainPage.OnBeaconEventAsync(): '"
                        + eventArgs.EventType + "' event from " + beacon.ToString());
				}

				bool isExistingBeacon = false;

                if (BeaconModel.Contains(beacon))
                {
                    if (eventArgs.EventType == BeaconEventType.Exit)
                    {
                        BeaconModel.Remove(beacon);
                    }
                    else
                    {
                        BeaconModel.AddOrReplace(beacon);
                    }

                    BeaconModel.SortBeaconsBasedOnDistance();
                    isExistingBeacon = true;
                }


                if (!isExistingBeacon)
				{
                    BeaconModel.AddOrReplace(beacon);
                    BeaconModel.SortBeaconsBasedOnDistance();
                }

				if (BeaconModel.Count() > 0)
				{
                    BeaconsInRange = true;
				}
				else
				{
                    BeaconsInRange = false;
                }
            });
		}
 /// <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);
     }
 }
 /// <summary>
 /// Called when the scanner detects a beacon.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private async void OnBeaconEventAsync(object sender, BeaconEventArgs e)
 {
     if (e.EventType != BeaconEventType.None)
     {
         await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(
             CoreDispatcherPriority.Normal, () =>
             {
                 AddLogEntry("Received event '" + e.EventType + "' from beacon " + e.Beacon.ToString());
             });
     }
 }
 private void AddBeaconArgs(Beacon beacon, BeaconEventType eventType)
 {
     var args = new BeaconEventArgs();
     args.Beacon = beacon;
     args.EventType = eventType;
     _beaconArgs.Add(args);
 }