Beispiel #1
0
 /// <summary>
 /// Event handler for VisitStateChanged events. It is raised when
 /// a new visit state change is available based on the monitoring scope specified.
 /// </summary>
 /// <param name="sender">Geovisitmonitor instance</param>
 /// <param name="args">VisitStateChanged args data</param>
 async private void OnVisitStateChanged(GeovisitMonitor sender, GeovisitStateChangedEventArgs args)
 {
     await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
     {
         _rootPage.NotifyUser("Visit state changed.", NotifyType.StatusMessage);
         UpdateVisitData(args.Visit);
     });
 }
Beispiel #2
0
        /// <summary>
        /// This is the click handler for the 'StopMonitoring' button.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void StopMonitoring(object sender, RoutedEventArgs e)
        {
            // Stop visit monitoring.
            _visitMonitor.Stop();
            _visitMonitor = null;

            StartMonitoringButton.IsEnabled = true;
            StopMonitoringButton.IsEnabled  = false;

            // Clear status
            _rootPage.NotifyUser("", NotifyType.StatusMessage);
        }
Beispiel #3
0
        /// <summary>
        /// This is the click handler for the 'StartMonitoring' button.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void StartMonitoring(object sender, RoutedEventArgs e)
        {
            // Request permission to access location
            var accessStatus = await Geolocator.RequestAccessAsync();

            switch (accessStatus)
            {
            case GeolocationAccessStatus.Allowed:

                _visitMonitor = new GeovisitMonitor();

                // Add visit state changed event handler.
                _visitMonitor.VisitStateChanged += OnVisitStateChanged;

                // Start monitoring with the desired scope.
                // For higher granularity such as building/venue level changes, choose venue.
                // For lower granularity more or less in the range of zipcode level changes, choose city.
                // Choosing Venue here as an example.
                _visitMonitor.Start(VisitMonitoringScope.Venue);

                LocationDisabledMessage.Visibility = Visibility.Collapsed;
                _rootPage.NotifyUser("Waiting for update...", NotifyType.StatusMessage);

                StartMonitoringButton.IsEnabled = false;
                StopMonitoringButton.IsEnabled  = true;
                break;

            case GeolocationAccessStatus.Denied:
                _rootPage.NotifyUser("Access to location is denied.", NotifyType.ErrorMessage);
                LocationDisabledMessage.Visibility = Visibility.Visible;
                break;

            default:
            case GeolocationAccessStatus.Unspecified:
                _rootPage.NotifyUser("Unspecificed error!", NotifyType.ErrorMessage);
                LocationDisabledMessage.Visibility = Visibility.Collapsed;
                break;
            }
        }
        /// <summary>
        /// This is the click handler for the 'getLastVisit' button.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void GetLastVisitButtonClicked(object sender, RoutedEventArgs e)
        {
            GetLastVisitButton.IsEnabled       = false;
            LocationDisabledMessage.Visibility = Visibility.Collapsed;

            // Request permission to access location
            var accessStatus = await Geolocator.RequestAccessAsync();

            Geovisit visit = null;

            switch (accessStatus)
            {
            case GeolocationAccessStatus.Allowed:
                _rootPage.NotifyUser("Waiting for update...", NotifyType.StatusMessage);

                // Get the last visit report, if any. This should be a quick operation.
                visit = await GeovisitMonitor.GetLastReportAsync();

                _rootPage.NotifyUser("Visit info updated.", NotifyType.StatusMessage);
                break;

            case GeolocationAccessStatus.Denied:
                _rootPage.NotifyUser("Access to location is denied.", NotifyType.ErrorMessage);
                LocationDisabledMessage.Visibility = Visibility.Visible;
                break;

            default:
            case GeolocationAccessStatus.Unspecified:
                _rootPage.NotifyUser("Unspecified error.", NotifyType.ErrorMessage);
                break;
            }

            UpdateLastVisit(visit);

            GetLastVisitButton.IsEnabled = true;
        }