protected override IEnumerable <Datum> Poll(CancellationToken cancellationToken) { List <Datum> data = new List <Datum>(); Position currentPosition = GpsReceiver.Get().GetReading(cancellationToken, false); if (currentPosition == null) { throw new Exception("Failed to get GPS reading."); } else { foreach (PointOfInterest pointOfInterest in SensusServiceHelper.Get().PointsOfInterest.Union(Protocol.PointsOfInterest)) // POIs are stored on the service helper (e.g., home locations) and the Protocol (e.g., bars), since the former are user-specific and the latter are universal. { double distanceToPointOfInterestMeters = pointOfInterest.KmDistanceTo(currentPosition) * 1000; foreach (PointOfInterestProximityTrigger trigger in _triggers) { if (pointOfInterest.Triggers(trigger, distanceToPointOfInterestMeters)) { data.Add(new PointOfInterestProximityDatum(currentPosition.Timestamp, pointOfInterest, distanceToPointOfInterestMeters, trigger)); } } } } if (data.Count == 0) { data.Add(null); } return(data); }
protected sealed override async Task <List <Datum> > PollAsync(CancellationToken cancellationToken) { Position currentPosition = await GpsReceiver.Get().GetReadingAsync(cancellationToken, false); if (currentPosition == null) { throw new Exception("Failed to get GPS reading."); } else { return(new Datum[] { new LocationDatum(currentPosition.Timestamp, currentPosition.Accuracy, currentPosition.Latitude, currentPosition.Longitude) }.ToList()); } }
protected sealed override IEnumerable <Datum> Poll(CancellationToken cancellationToken) { Position currentPosition = GpsReceiver.Get().GetReading(cancellationToken); if (currentPosition == null) { throw new Exception("Failed to get GPS reading."); } else { return new Datum[] { new LocationDatum(currentPosition.Timestamp, currentPosition.Accuracy, currentPosition.Latitude, currentPosition.Longitude) } }; }
public PointOfInterestProximityTrigger(string pointOfInterestName, string pointOfInterestType, double distanceThresholdMeters, ProximityThresholdDirection distanceThresholdDirection) : this() { if (string.IsNullOrWhiteSpace(pointOfInterestName) && string.IsNullOrWhiteSpace(pointOfInterestType)) { throw new Exception("No POI was supplied."); } else if (distanceThresholdMeters <= 0) { throw new Exception("Invalid distance threshold. Must be greater than zero."); } else if (distanceThresholdMeters < GpsReceiver.Get().MinimumDistanceThreshold) { throw new Exception("Distance threshold must be at least " + GpsReceiver.Get().MinimumDistanceThreshold + "."); } _pointOfInterestName = pointOfInterestName; _pointOfInterestType = pointOfInterestType; _distanceThresholdMeters = distanceThresholdMeters; _distanceThresholdDirection = distanceThresholdDirection; }
protected sealed override void StopListening() { GpsReceiver.Get().RemoveListener(_positionChangedHandler); }
protected sealed override void StartListening() { GpsReceiver.Get().AddListener(_positionChangedHandler, false); }
protected override async Task StopListeningAsync() { await base.StopListeningAsync(); await GpsReceiver.Get().RemoveListenerAsync(_positionChangedHandler); }
protected override async Task StartListeningAsync() { await base.StartListeningAsync(); await GpsReceiver.Get().AddListenerAsync(_positionChangedHandler, false); }