Exemple #1
0
 public PointOfInterestProximityDatum(DateTimeOffset timestamp, PointOfInterest pointOfInterest, double distanceMeters, PointOfInterestProximityTrigger trigger)
     : base(timestamp)
 {
     _poiName                  = pointOfInterest.Name;
     _poiType                  = pointOfInterest.Type;
     _poiLatitude              = pointOfInterest.Position.Latitude;
     _poiLongitude             = pointOfInterest.Position.Longitude;
     _distanceToPoiMeters      = distanceMeters;
     _triggerDistanceMeters    = trigger.DistanceThresholdMeters;
     _triggerDistanceDirection = trigger.DistanceThresholdDirection;
 }
 public PointOfInterestProximityDatum(DateTimeOffset timestamp, PointOfInterest pointOfInterest, double distanceMeters, PointOfInterestProximityTrigger trigger)
     : base(timestamp)
 {
     _poiName = pointOfInterest.Name;
     _poiType = pointOfInterest.Type;
     _poiLatitude = pointOfInterest.Position.Latitude;
     _poiLongitude = pointOfInterest.Position.Longitude;
     _distanceToPoiMeters = distanceMeters;
     _triggerDistanceMeters = trigger.DistanceThresholdMeters;
     _triggerDistanceDirection = trigger.DistanceThresholdDirection;
 }
        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.");

            _pointOfInterestName = pointOfInterestName;
            _pointOfInterestType = pointOfInterestType;
            _distanceThresholdMeters = distanceThresholdMeters;
            _distanceThresholdDirection = distanceThresholdDirection;
        }
        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;
        }
Exemple #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AddProximityTriggerPage"/> class.
        /// </summary>
        /// <param name="proximityProbe">Proximity probe to add trigger to.</param>
        public AddProximityTriggerPage(IPointsOfInterestProximityProbe proximityProbe)
        {
            _proximityProbe = proximityProbe;

            Title = "Add Trigger";

            List <PointOfInterest> pointsOfInterest = SensusServiceHelper.Get().PointsOfInterest.Union(_proximityProbe.Protocol.PointsOfInterest).ToList();

            if (pointsOfInterest.Count == 0)
            {
                Content = new Label
                {
                    Text     = "No points of interest defined. Please define one or more before creating triggers.",
                    FontSize = 20
                };

                return;
            }

            StackLayout contentLayout = new StackLayout
            {
                Orientation     = StackOrientation.Vertical,
                VerticalOptions = LayoutOptions.FillAndExpand
            };

            #region point of interest
            Label pointOfInterestLabel = new Label
            {
                Text     = "POI:",
                FontSize = 20
            };

            Picker pointOfInterestPicker = new Picker
            {
                Title             = "Select POI",
                HorizontalOptions = LayoutOptions.FillAndExpand
            };

            foreach (string poiDesc in pointsOfInterest.Select(poi => poi.ToString()))
            {
                pointOfInterestPicker.Items.Add(poiDesc);
            }

            pointOfInterestPicker.SelectedIndexChanged += (o, e) =>
            {
                if (pointOfInterestPicker.SelectedIndex < 0)
                {
                    _pointOfInterestName = _pointOfInterestType = null;
                }
                else
                {
                    PointOfInterest poi = pointsOfInterest[pointOfInterestPicker.SelectedIndex];
                    _pointOfInterestName = poi.Name;
                    _pointOfInterestType = poi.Type;
                }
            };

            contentLayout.Children.Add(new StackLayout
            {
                Orientation       = StackOrientation.Horizontal,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                Children          = { pointOfInterestLabel, pointOfInterestPicker }
            });
            #endregion

            #region distance threshold
            Label distanceThresholdLabel = new Label
            {
                Text     = "Distance Threshold (Meters):",
                FontSize = 20
            };

            Entry distanceThresholdEntry = new Entry
            {
                HorizontalOptions = LayoutOptions.FillAndExpand,
                Keyboard          = Keyboard.Numeric
            };

            distanceThresholdEntry.TextChanged += async(o, e) =>
            {
                if (!double.TryParse(distanceThresholdEntry.Text, out _distanceThresholdMeters))
                {
                    _distanceThresholdMeters = -1;
                }
                else if (_distanceThresholdMeters < GpsReceiver.Get().MinimumDistanceThreshold)
                {
                    await SensusServiceHelper.Get().FlashNotificationAsync("Distance threshold must be at least " + GpsReceiver.Get().MinimumDistanceThreshold + ".");
                }
            };

            contentLayout.Children.Add(new StackLayout
            {
                Orientation       = StackOrientation.Horizontal,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                Children          = { distanceThresholdLabel, distanceThresholdEntry }
            });
            #endregion

            #region threshold direction
            Label thresholdDirectionLabel = new Label
            {
                Text     = "Threshold Direction:",
                FontSize = 20
            };

            ProximityThresholdDirection[] thresholdDirections = new ProximityThresholdDirection[] { ProximityThresholdDirection.Within, ProximityThresholdDirection.Outside };
            Picker thresholdDirectionPicker = new Picker
            {
                Title             = "Select Threshold Direction",
                HorizontalOptions = LayoutOptions.FillAndExpand
            };

            foreach (ProximityThresholdDirection thresholdDirection in thresholdDirections)
            {
                thresholdDirectionPicker.Items.Add(thresholdDirection.ToString());
            }

            thresholdDirectionPicker.SelectedIndexChanged += (o, e) =>
            {
                if (thresholdDirectionPicker.SelectedIndex < 0)
                {
                    _thresholdDirection = ProximityThresholdDirection.Within;
                }
                else
                {
                    _thresholdDirection = thresholdDirections[thresholdDirectionPicker.SelectedIndex];
                }
            };

            contentLayout.Children.Add(new StackLayout
            {
                Orientation       = StackOrientation.Horizontal,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                Children          = { thresholdDirectionLabel, thresholdDirectionPicker }
            });
            #endregion

            Button okButton = new Button
            {
                Text     = "OK",
                FontSize = 20
            };

            okButton.Clicked += async(o, e) =>
            {
                try
                {
                    _proximityProbe.Triggers.Add(new PointOfInterestProximityTrigger(_pointOfInterestName, _pointOfInterestType, _distanceThresholdMeters, _thresholdDirection));
                    await Navigation.PopAsync();
                }
                catch (Exception ex)
                {
                    string message = "Failed to add trigger:  " + ex.Message;
                    await SensusServiceHelper.Get().FlashNotificationAsync(message);

                    SensusServiceHelper.Get().Logger.Log(message, LoggingLevel.Normal, GetType());
                }
            };

            contentLayout.Children.Add(okButton);

            Content = new ScrollView
            {
                Content = contentLayout
            };
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="SensusUI.AddProximityTriggerPage"/> class.
        /// </summary>
        /// <param name="proximityProbe">Proximity probe to add trigger to.</param>
        public AddProximityTriggerPage(IPointsOfInterestProximityProbe proximityProbe)
        {
            _proximityProbe = proximityProbe;

            Title = "Add Trigger";

            List<PointOfInterest> pointsOfInterest = UiBoundSensusServiceHelper.Get(true).PointsOfInterest.Union(_proximityProbe.Protocol.PointsOfInterest).ToList();
            if (pointsOfInterest.Count == 0)
            {
                Content = new Label
                {
                    Text = "No points of interest defined. Please define one or more before creating triggers.",
                    FontSize = 20
                };

                return;
            }

            StackLayout contentLayout = new StackLayout
            {
                Orientation = StackOrientation.Vertical,
                VerticalOptions = LayoutOptions.FillAndExpand
            };

            #region point of interest
            Label pointOfInterestLabel = new Label
            {
                Text = "POI:",
                FontSize = 20
            };

            Picker pointOfInterestPicker = new Picker
            {
                Title = "Select POI",
                HorizontalOptions = LayoutOptions.FillAndExpand
            };

            foreach (string poiDesc in pointsOfInterest.Select(poi => poi.ToString()))
                pointOfInterestPicker.Items.Add(poiDesc);

            pointOfInterestPicker.SelectedIndexChanged += (o, e) =>
            {
                if (pointOfInterestPicker.SelectedIndex < 0)
                    _pointOfInterestName = _pointOfInterestType = null;
                else
                {
                    PointOfInterest poi = pointsOfInterest[pointOfInterestPicker.SelectedIndex];
                    _pointOfInterestName = poi.Name;
                    _pointOfInterestType = poi.Type;
                }
            };

            contentLayout.Children.Add(new StackLayout
                {
                    Orientation = StackOrientation.Horizontal,
                    HorizontalOptions = LayoutOptions.FillAndExpand,
                    Children = { pointOfInterestLabel, pointOfInterestPicker }
                });
            #endregion

            #region distance threshold
            Label distanceThresholdLabel = new Label
            {
                Text = "Distance Threshold (Meters):",
                FontSize = 20
            };

            Entry distanceThresholdEntry = new Entry
            {
                HorizontalOptions = LayoutOptions.FillAndExpand,
                Keyboard = Keyboard.Numeric
            };

            distanceThresholdEntry.TextChanged += (o, e) =>
            {
                if (!double.TryParse(distanceThresholdEntry.Text, out _distanceThresholdMeters))
                    _distanceThresholdMeters = -1;
                else if (_distanceThresholdMeters < GpsReceiver.Get().MinimumDistanceThreshold)
                    UiBoundSensusServiceHelper.Get(true).FlashNotificationAsync("Distance threshold must be at least " + GpsReceiver.Get().MinimumDistanceThreshold + ".");
            };

            contentLayout.Children.Add(new StackLayout
                {
                    Orientation = StackOrientation.Horizontal,
                    HorizontalOptions = LayoutOptions.FillAndExpand,
                    Children = { distanceThresholdLabel, distanceThresholdEntry }
                });
            #endregion

            #region threshold direction
            Label thresholdDirectionLabel = new Label
            {
                Text = "Threshold Direction:",
                FontSize = 20
            };

            ProximityThresholdDirection[] thresholdDirections = new ProximityThresholdDirection[]{ ProximityThresholdDirection.Within, ProximityThresholdDirection.Outside };
            Picker thresholdDirectionPicker = new Picker
            {
                Title = "Select Threshold Direction",
                HorizontalOptions = LayoutOptions.FillAndExpand
            };

            foreach (ProximityThresholdDirection thresholdDirection in thresholdDirections)
                thresholdDirectionPicker.Items.Add(thresholdDirection.ToString());

            thresholdDirectionPicker.SelectedIndexChanged += (o, e) =>
            {
                if (thresholdDirectionPicker.SelectedIndex < 0)
                    _thresholdDirection = ProximityThresholdDirection.Within;
                else
                    _thresholdDirection = thresholdDirections[thresholdDirectionPicker.SelectedIndex];
            };

            contentLayout.Children.Add(new StackLayout
                {
                    Orientation = StackOrientation.Horizontal,
                    HorizontalOptions = LayoutOptions.FillAndExpand,
                    Children = { thresholdDirectionLabel, thresholdDirectionPicker }
                });
            #endregion

            Button okButton = new Button
            {
                Text = "OK",
                FontSize = 20
            };

            okButton.Clicked += async (o, e) =>
            {
                try
                {
                    _proximityProbe.Triggers.Add(new PointOfInterestProximityTrigger(_pointOfInterestName, _pointOfInterestType, _distanceThresholdMeters, _thresholdDirection));
                    UiBoundSensusServiceHelper.Get(true).SaveAsync();
                    await Navigation.PopAsync();
                }
                catch (Exception ex)
                {
                    string message = "Failed to add trigger:  " + ex.Message;
                    UiBoundSensusServiceHelper.Get(true).FlashNotificationAsync(message);
                    UiBoundSensusServiceHelper.Get(true).Logger.Log(message, LoggingLevel.Normal, GetType());
                }
            };

            contentLayout.Children.Add(okButton);

            Content = new ScrollView
            {
                Content = contentLayout
            };
        }