private async void OnBeaconEventAsync(object sender, BeaconEventArgs eventArgs) { if (scannerControl != null) { await scannerControl.OnBeaconEvent(eventArgs); } }
private void AddBeaconArgs(Beacon beacon, BeaconEventType eventType) { var args = new BeaconEventArgs(); args.Beacon = beacon; args.EventType = eventType; _beaconArgs.Add(args); }
/// <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()); }); } }
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(); }
static void Bleep(BeaconEventArgs e) { var addr = e.Beacon.Uuid; var temp = e.Beacon.Major; var sg = e.Beacon.Minor / 1000.0; var power = e.Beacon.Rssi; // make sure it is a tilt hydrometer device if (addr.Contains("a495bb50")) { Console.WriteLine(addr + ": " + temp + "°C SG = " + sg + " Power = " + power + " dB"); } }
/// <summary> /// Tries to find a beacon action based on the given beacon event arguments. /// </summary> /// <param name="eventArgs">The arguments of a beacon event.</param> /// <returns></returns> public async Task ResolveBeaconAction(BeaconEventArgs eventArgs) { if (eventArgs == null) { return; } if (IsInitialized) { string location = await _locationService.GetGeoHashedLocation(); eventArgs.Location = location; await Resolver.CreateRequest(eventArgs); } }
public async Task<int> CreateRequest(BeaconEventArgs beaconEventArgs) { int requestId = SdkData.NextId(); Logger.Debug("Resolver: Beacon " + beaconEventArgs.Beacon.Id1 + " " + beaconEventArgs.Beacon.Id2 + " " + beaconEventArgs.Beacon.Id3 + " ---> Request: " + requestId); Request request = new Request(beaconEventArgs, requestId); if (SynchronResolver) { await Resolve(request); Finished?.Invoke(); } else { AddAsynchronRequest(request); } return requestId; }
private void BeaconDetected(BeaconEventArgs e) { var uuid = e.Beacon.Uuid; var temp = e.Beacon.Major; var sg = e.Beacon.Minor / 1000.0; var power = e.Beacon.Rssi; // make sure it is a tilt hydrometer device if (uuid.Contains("a495bb50")) { // fire event TiltHydrometerHubEventHandler mce = TiltHydrometerHubEvent; var ev = new TiltHydrometerHubEventArgs { RawEvent = e, Uuid = uuid, Power = power, SG = sg, Temp = temp }; mce?.Invoke(this, ev); } }
public async Task <int> CreateRequest(BeaconEventArgs beaconEventArgs) { int requestId = SdkData.NextId(); Logger.Debug("Resolver: Beacon " + beaconEventArgs.Beacon.Id1 + " " + beaconEventArgs.Beacon.Id2 + " " + beaconEventArgs.Beacon.Id3 + " ---> Request: " + requestId); Request request = new Request(beaconEventArgs, requestId); if (SynchronResolver) { await Resolve(request); Finished?.Invoke(); } else { AddAsynchronRequest(request); } return(requestId); }
public async Task OnBeaconEvent(BeaconEventArgs eventArgs) { try { Beacon beacon = eventArgs.Beacon; if (eventArgs.EventType != BeaconEventType.None) { Logger.Debug("MainPage.OnBeaconEventAsync: '" + eventArgs.EventType + "' event from " + beacon); } bool isExistingBeacon = false; if (BeaconModel.Contains(beacon)) { if (eventArgs.EventType == BeaconEventType.Exit) { await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Low, () => BeaconModel.Remove(beacon)); } else { BeaconModel.AddOrReplace(beacon); } isExistingBeacon = true; } if (!isExistingBeacon) { BeaconModel.AddOrReplace(beacon); } } catch (Exception e) { Logger.Error("Error while add/update beacon", e); } }
/// <summary> /// Stores a beacon event to the database. /// </summary> public async Task SaveBeaconEventAsync(BeaconEventArgs eventArgs, string location) { await ServiceManager.StorageService.SaveHistoryEvent(eventArgs.Beacon.Pid, eventArgs.Timestamp, eventArgs.EventType, location); }
/// <summary> /// Tries to find a beacon action based on the given beacon event arguments. /// </summary> /// <param name="eventArgs">The arguments of a beacon event.</param> /// <returns></returns> public async Task ResolveBeaconAction(BeaconEventArgs eventArgs) { if (IsInitialized && eventArgs != null && eventArgs.EventType != BeaconEventType.None) { UnresolvedActionCount++; Resolver.CreateRequest(eventArgs); await _eventHistory.SaveBeaconEventAsync(eventArgs); } }
private static void Pir_BeaconNotification(object sender, BeaconEventArgs e) { }
/// <summary> /// Constructor. /// </summary> /// <param name="beaconEventArgs">The beacon event details.</param> /// <param name="requestId">The request ID (can be arbitrary).</param> public Request(BeaconEventArgs beaconEventArgs, int requestId) { BeaconEventArgs = beaconEventArgs; RequestId = requestId; ResultState = RequestResultState.None; }
/// <summary> /// Stores a beacon event to the database. /// </summary> /// <param name="eventArgs"></param> public IAsyncAction SaveBeaconEventAsync(BeaconEventArgs eventArgs) { return _storage.SaveHistoryEventsAsync(eventArgs.Beacon.Pid, eventArgs.Timestamp, (int)eventArgs.EventType).AsAsyncAction(); }
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 }
/// <summary> /// Creates an new Request object. /// </summary> /// <param name="beaconEventArgs">The beacon event details.</param> /// <param name="requestId">The request ID (can be arbitrary).</param> public Request(BeaconEventArgs beaconEventArgs, int requestId) { BeaconEventArgs = beaconEventArgs; RequestId = requestId; ResultState = RequestResultState.None; }