protected override IEnumerable <Datum> Poll(CancellationToken cancellationToken)
        {
            List <Datum> data = new List <Datum>();

            Position currentPosition = GpsReceiver.Get().GetReading(cancellationToken);

            if (currentPosition != null)
            {
                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);
        }
Пример #2
0
        protected override void Initialize()
        {
            base.Initialize();

            if (!GpsReceiver.Get().Locator.IsGeolocationEnabled)
            {
                string error = "Geolocation is not enabled on this device. Cannot start location probe.";
                SensusServiceHelper.Get().FlashNotificationAsync(error);
                throw new Exception(error);
            }
        }
Пример #3
0
        protected override void Initialize()
        {
            base.Initialize();

            if (!GpsReceiver.Get().Locator.IsGeolocationEnabled)
            {
                // throw standard exception instead of NotSupportedException, since the user might decide to enable GPS in the future
                // and we'd like the probe to be restarted at that time.
                string error = "Geolocation is not enabled on this device. Cannot start location probe.";
                SensusServiceHelper.Get().FlashNotificationAsync(error);
                throw new Exception(error);
            }
        }
Пример #4
0
        protected sealed override IEnumerable <Datum> Poll(CancellationToken cancellationToken)
        {
            Position reading = GpsReceiver.Get().GetReading(cancellationToken);

            if (reading == null)
            {
                return new Datum[] { }
            }
            ;
            else
            {
                return new Datum[] { new LocationDatum(reading.Timestamp, reading.Accuracy, reading.Latitude, reading.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;
        }
Пример #6
0
 protected sealed override void StopListening()
 {
     GpsReceiver.Get().RemoveListener(_positionChangedHandler);
 }
Пример #7
0
 protected sealed override void StartListening()
 {
     GpsReceiver.Get().AddListener(_positionChangedHandler);
 }