Пример #1
0
        public async void OnGeofenceStateChangedHandler(GeofenceMonitor sender, object e)
        {
            bool tagsChanged = false;
            var  reports     = sender.ReadReports();


            foreach (GeofenceStateChangeReport report in reports)
            {
                GeofenceState state = report.NewState;

                Geofence geofence = report.Geofence;

                if (!String.Equals(geofence.Id, triggerFenceName))
                {
                    if (state == GeofenceState.Removed)
                    {
                    }
                    else if (state == GeofenceState.Entered)
                    {
                        tags.Add(geofence.Id);
                        tagsChanged = true;
                    }
                    else if (state == GeofenceState.Exited)
                    {
                        tags.RemoveAll(x => String.Equals(x, geofence.Id));
                        tagsChanged = true;
                    }
                }
            }

            if (tagsChanged)
            {
                await hub.RegisterAsync(GenerateRegistration());
            }
        }
Пример #2
0
 private async void Current_StatusChanged(GeofenceMonitor sender, object args)
 {
     await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
     {
         geofencingStatusTextBlock.Text = $"Geofencing Current status: {sender.Status} ({DateTime.Now}) (status changed)";
     });
 }
Пример #3
0
        private void HandleGeofenceStateChanged(GeofenceMonitor monitor, Object o)
        {
            // Iterate over and process the accumulated reports
            var reports = monitor.ReadReports();

            foreach (var report in reports)
            {
                switch (report.NewState)
                {
                case GeofenceState.Entered:
                case GeofenceState.Exited:
                    var updateArgs = new FenceUpdateEventArgs
                    {
                        FenceId   = report.Geofence.Id,
                        Reason    = report.NewState.ToString(),
                        Position  = report.Geoposition.Coordinate.Point.Position,
                        Timestamp = report.Geoposition.Coordinate.Timestamp
                    };
                    OnFenceUpdated(updateArgs);
                    break;

                case GeofenceState.Removed:
                    var removedArgs = new FenceRemovedEventArgs
                    {
                        FenceId    = report.Geofence.Id,
                        WhyRemoved = report.RemovalReason.ToString()
                    };
                    OnFenceRemoved(removedArgs);

                    break;
                }
            }
        }
Пример #4
0
        //围栏被触发委托
        private async void Current_GeofenceStateChanged(GeofenceMonitor sender, object args)
        {
            var reports = sender.ReadReports();

            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                foreach (GeofenceStateChangeReport report in reports)
                {
                    GeofenceState state = report.NewState;

                    Geofence geofence = report.Geofence;

                    if (state == GeofenceState.Removed)
                    {
                        // Remove the geofence from the geofences collection.
                        GeofenceMonitor.Current.Geofences.Remove(geofence);
                    }
                    else if (state == GeofenceState.Entered)
                    {
                        // Your app takes action based on the entered event.

                        // NOTE: You might want to write your app to take a particular
                        // action based on whether the app has internet connectivity.
                    }
                    else if (state == GeofenceState.Exited)
                    {
                        // Your app takes action based on the exited event.

                        // NOTE: You might want to write your app to take a particular
                        // action based on whether the app has internet connectivity.
                    }
                }
            });
        }
Пример #5
0
        /// STEP 1B: On geofence monitor status change, read status and proceed accordingly
        /// Event handler for geofence monitor status changes.
        /// </summary>
        /// <param name="sender">GeofenceMonitor, which receives the event notifications.</param>
        /// <param name="e">Event data that describes how this page was reached.  The Parameter
        /// property is typically used to configure the page.</param>
        public async void OnStatusChangedHandler(GeofenceMonitor sender, object e)
        {
            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                var status = sender.Status;

                string eventDescription = "Geofence Status Changed: ";

                if (GeofenceMonitorStatus.Ready == status)
                {
                    Debug.WriteLine(eventDescription + " (Ready)");
                }
                else if (GeofenceMonitorStatus.Initializing == status)
                {
                    Debug.WriteLine(eventDescription + " (Initializing)");
                }
                else if (GeofenceMonitorStatus.NoData == status)
                {
                    Debug.WriteLine(eventDescription + " (NoData)");
                }
                else if (GeofenceMonitorStatus.Disabled == status)
                {
                    Debug.WriteLine(eventDescription + " (Disabled)");
                }
                else if (GeofenceMonitorStatus.NotInitialized == status)
                {
                    Debug.WriteLine(eventDescription + " (NotInitialized)");
                }
                else if (GeofenceMonitorStatus.NotAvailable == status)
                {
                    Debug.WriteLine(eventDescription + " (NotAvailable)");
                }
            });
        }
Пример #6
0
        public void OnGeofenceStateChangedHandler(GeofenceMonitor sender, object e)
        {
            var reports = sender.ReadReports();

            foreach (GeofenceStateChangeReport report in reports)
            {
                GeofenceState state = report.NewState;

                Geofence geofence = report.Geofence;


                if (state == GeofenceState.Removed)
                {
                }
                else if (state == GeofenceState.Entered)
                {
                }
                else if (state == GeofenceState.Exited)
                {
                    if (String.Equals(geofence.Id, TriggerFence.Id))
                    {
                        // They have left the area for which we have fences loaded,
                        // trigger a reload
                        BasicGeoposition current = sender.LastKnownGeoposition.ToBasicGeoposition();
                        RefreshTriggerFence(current);
                        RefreshArmedFences(current);
                    }
                }
            }
        }
Пример #7
0
        /// <summary>
        /// Event handler for GeoFence entry and exits
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private async void OnGeoFenceStateChanged(GeofenceMonitor sender, object args)
        {
            var reports = sender.ReadReports();

            foreach (GeofenceStateChangeReport report in reports)
            {
                GeofenceState state = report.NewState;

                Geofence geofence = report.Geofence;

                if (state == GeofenceState.Removed)
                {
                    report.Geofence.Id.ToString();
                    // remove the geofence from the geofences collection
                    GeofenceMonitor.Current.Geofences.Remove(geofence);
                }
                else if (state == GeofenceState.Entered)
                {
                    if (_manualTrigger == false)
                    {
                        _deferral.Complete();
                    }
                }
                else if (state == GeofenceState.Exited)
                {
                }
            }
        }
 public GeofenceRegistrationManager(string hubName, string hubConnectionString, string pushChannel)
 {
     this.tags = new List<string>();
     this.hub = new NotificationHub(hubName, hubConnectionString);
     this.pushChannel = pushChannel;
     this.monitor = GeofenceMonitor.Current;
     this.monitor.GeofenceStateChanged += OnGeofenceStateChangedHandler;    
 }
Пример #9
0
 public GeofenceRegistrationManager(string hubName, string hubConnectionString, string pushChannel)
 {
     this.tags        = new List <string>();
     this.hub         = new NotificationHub(hubName, hubConnectionString);
     this.pushChannel = pushChannel;
     this.monitor     = GeofenceMonitor.Current;
     this.monitor.GeofenceStateChanged += OnGeofenceStateChangedHandler;
 }
Пример #10
0
        private void OnGeofenceStateChanged(GeofenceMonitor sender, object args)
        {
            var reports =
                GeofenceMonitor.Current.ReadReports()
                .Where(report => report.NewState == GeofenceState.Entered)
                .Select(report => report.Geofence.Id);

            ViewModel.OnGeofenceInForeground(reports);
        }
Пример #11
0
 public GeofenceLoader(Uri serviceAddress)
 {
     this.client = new HttpClient
     {
         BaseAddress = serviceAddress
     };
     this.monitor = GeofenceMonitor.Current;
     this.monitor.GeofenceStateChanged += OnGeofenceStateChangedHandler;
     this.TriggerFence = null;
     this.ArmedFences  = new List <Geofence>();
 }
        public async void OnGeofenceStatusChanged(GeofenceMonitor sender, object e)
        {
            GeofenceMonitorStatus status = sender.Status;

            string eventDescription = "Geofence Status Changed " + DateTime.Now.ToString("T") + " (" + status.ToString() + ")";

            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                AddEventDescription(eventDescription);
            });
        }
Пример #13
0
        void myMonitor_GeofenceStateChanged(GeofenceMonitor sender, object args)
        {
            var getReport = sender.ReadReports();

            foreach (var report in getReport)
            {
                if (report.Geofence.Id == "btsvm")
                {
                    if (report.NewState == GeofenceState.Entered)
                    {
                        Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
                        {
                            //TextBlock tb = new TextBlock();
                            //tb.Text = "Welcome to BTS Victory Monument";
                            //reportField.Children.Add(tb);

                            var notifier = ToastNotificationManager.CreateToastNotifier();
                            notifier.Show(BuildToast("Welcome to BTS Victory Monument"));
                        });
                    }
                    else if (report.NewState == GeofenceState.Exited)
                    {
                        Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
                        {
                            TextBlock tb = new TextBlock();
                            tb.Text      = "Exit from BTS Victory Monument";
                            reportField.Children.Add(tb);
                        });
                    }
                }
                else if (report.Geofence.Id == "payathai")
                {
                    if (report.NewState == GeofenceState.Entered)
                    {
                        Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
                        {
                            TextBlock tb = new TextBlock();
                            tb.Text      = "Welcome to Payathai";
                            reportField.Children.Add(tb);
                        });
                    }
                    else if (report.NewState == GeofenceState.Exited)
                    {
                        Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
                        {
                            TextBlock tb = new TextBlock();
                            tb.Text      = "Exit from Payathai";
                            reportField.Children.Add(tb);
                        });
                    }
                }
            }
        }
Пример #14
0
        public async void OnGeofenceStatusChanged(GeofenceMonitor sender, object e)
        {
            var status = sender.Status;

            string eventDescription = GetTimeStampedMessage("Geofence Status Changed");

            eventDescription += " (" + status.ToString() + ")";

            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                AddEventDescription(eventDescription);
            });
        }
Пример #15
0
        public GeofenceLoader(Uri serviceAddress)
        {
            this.client = new HttpClient
            {
                BaseAddress = serviceAddress
                
            };
            this.monitor = GeofenceMonitor.Current;
            this.monitor.GeofenceStateChanged += OnGeofenceStateChangedHandler;       
            this.TriggerFence = null;
            this.ArmedFences = new List<Geofence>();

        }
Пример #16
0
        private static void OnGeofenceStateChanged(GeofenceMonitor sender, object e)
        {
            var reports = sender.ReadReports();

            if (Dispatcher != null)
            {
                Dispatcher.BeginInvoke(() =>
                {
                    OnGeofenceStateChanged(reports);
                });
            }
            else
            {
                OnGeofenceStateChanged(reports);
            }
        }
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            Window.Current.VisibilityChanged += OnVisibilityChanged;

            DateTime oneHourLater = DateTime.Now.AddHours(1);

            //rjc/$$
            StartDate.Date = oneHourLater.Date;
            StartTime.Time = oneHourLater.TimeOfDay;

            // Get permission to use location
            GeolocationAccessStatus accessStatus = await Geolocator.RequestAccessAsync();

            switch (accessStatus)
            {
            case GeolocationAccessStatus.Allowed:
                // Wrap in try/catch in case user revokes access suddenly.
                try
                {
                    geofenceMonitor = GeofenceMonitor.Current;
                }
                catch (UnauthorizedAccessException)
                {
                    _rootPage.NotifyUser("Access denied.", NotifyType.ErrorMessage);
                }
                if (geofenceMonitor != null)
                {
                    foreach (Geofence geofence in geofenceMonitor.Geofences)
                    {
                        AddGeofenceToRegisteredGeofenceListBox(geofence);
                    }

                    // register for state change events
                    geofenceMonitor.GeofenceStateChanged += OnGeofenceStateChanged;
                    geofenceMonitor.StatusChanged        += OnGeofenceStatusChanged;
                }
                break;

            case GeolocationAccessStatus.Denied:
                _rootPage.NotifyUser("Access denied.", NotifyType.ErrorMessage);
                break;

            case GeolocationAccessStatus.Unspecified:
                _rootPage.NotifyUser("Unspecified error.", NotifyType.ErrorMessage);
                break;
            }
        }
Пример #18
0
        private void Current_GeofenceStateChanged(GeofenceMonitor sender, object args)
        {
            var change_reports = sender.ReadReports();

            foreach (var change_report in change_reports)
            {
                var new_state = change_report.NewState;
                if (new_state == GeofenceState.Entered)
                {
                    AttendaceChanged?.Invoke(1);
                }
                else if (new_state == GeofenceState.Exited)
                {
                    AttendaceChanged?.Invoke(-1);
                }
            }
        }
        private async void Current_StatusChanged(GeofenceMonitor sender, object args)
        {
            var reports = sender.ReadReports();

            await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                foreach (GeofenceStateChangeReport report in reports)
                {
                    GeofenceState state = report.NewState;

                    Geofence geofence       = report.Geofence;
                    string eventDescription = string.Format("{0} ({1})", geofence.Id, state.ToString());

                    Debug.WriteLine(eventDescription);
                }
            });
        }
Пример #20
0
        public MainPage()
        {
            this.InitializeComponent();
            this.monitor = GeofenceMonitor.Current;

            currentLocationPushpin = new Pushpin();
            currentLocationPushpin.Background = new SolidColorBrush(Colors.Black);
          
            myMap.Children.Add(currentLocationPushpin);
            
            loader = new GeofenceLoader(new Uri("http://localhost:1337"));
            loader.PropertyChanged += loader_PropertyChanged;

            monitor = GeofenceMonitor.Current;

            locator = new Geolocator();
            locator.MovementThreshold = 10;
            locator.PositionChanged += locator_PositionChanged;
        }
Пример #21
0
        //位置权限更改委托
        private async void Current_StatusChanged(GeofenceMonitor sender, object args)
        {
            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                // Show the location setting message only if the status is disabled.
                // LocationDisabledMessage.Visibility = Visibility.Collapsed;

                switch (sender.Status)
                {
                case GeofenceMonitorStatus.Ready:
                    // _rootPage.NotifyUser("The monitor is ready and active.", NotifyType.StatusMessage);
                    break;

                case GeofenceMonitorStatus.Initializing:
                    //  _rootPage.NotifyUser("The monitor is in the process of initializing.", NotifyType.StatusMessage);
                    break;

                case GeofenceMonitorStatus.NoData:
                    //  _rootPage.NotifyUser("There is no data on the status of the monitor.", NotifyType.ErrorMessage);
                    break;

                case GeofenceMonitorStatus.Disabled:
                    //  _rootPage.NotifyUser("Access to location is denied.", NotifyType.ErrorMessage);

                    // Show the message to the user to go to the location settings.
                    //   LocationDisabledMessage.Visibility = Visibility.Visible;
                    break;

                case GeofenceMonitorStatus.NotInitialized:
                    //  _rootPage.NotifyUser("The geofence monitor has not been initialized.", NotifyType.StatusMessage);
                    break;

                case GeofenceMonitorStatus.NotAvailable:
                    //   _rootPage.NotifyUser("The geofence monitor is not available.", NotifyType.ErrorMessage);
                    break;

                default:
                    //  ScenarioOutput_Status.Text = "Unknown";
                    // _rootPage.NotifyUser(string.Empty, NotifyType.StatusMessage);
                    break;
                }
            });
        }
Пример #22
0
        /// <summary>
        /// Protocol on reaching Gungnir
        /// </summary>
        private async void Current_GeofenceStateChanged(GeofenceMonitor sender, object e)
        {
            System.Diagnostics.Debug.WriteLine("Entered geofence");
            var reports = sender.ReadReports();
            await MainPage.dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
            {
                foreach (var item in reports)
                {
                    var state = item.NewState;

                    if (state == GeofenceState.Entered)
                    {
                        SpearHandler.EndTimeRecord();
                        await SatanController.ShowMessageAsync("Gungnir", "You have retrieved Gungnir!");
                        ClearRoute();
                        SpearHandler.EndThrow();
                    }
                }
            });
        }
Пример #23
0
        /// <summary>
        /// Evento que se lanza cada vez que entra o sale del área.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private void MonitorOnGeofenceStateChanged(GeofenceMonitor sender, object args)
        {
            var fences = sender.ReadReports();

            foreach (var report in fences)
            {
                if (report.Geofence.Id != "Windows Phone Developer")
                    continue;

                switch (report.NewState)
                {
                    case GeofenceState.Entered:
                        _dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
                        {
                            await _dialogService.Show("Hola!");
                        });
                        break;
                }
            }
        }
Пример #24
0
        public async void OnGeofenceStateChanged(GeofenceMonitor sender, object e)
        {
            var reports = sender.ReadReports();

            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                foreach (GeofenceStateChangeReport report in reports)
                {
                    GeofenceState state = report.NewState;

                    Geofence geofence       = report.Geofence;
                    string eventDescription = GetTimeStampedMessage(geofence.Id);

                    eventDescription += " (" + state.ToString();

                    if (state == GeofenceState.Removed)
                    {
                        eventDescription += "/" + report.RemovalReason.ToString() + ")";

                        AddEventDescription(eventDescription);

                        // remove the geofence from the client side geofences collection
                        Remove(geofence);

                        // empty the registered geofence listbox and repopulate
                        geofenceCollection.Clear();

                        FillRegisteredGeofenceListBoxWithExistingGeofences();
                    }
                    else if (state == GeofenceState.Entered || state == GeofenceState.Exited)
                    {
                        // NOTE: You might want to write your app to take particular
                        // action based on whether the app has internet connectivity.

                        eventDescription += ")";

                        AddEventDescription(eventDescription);
                    }
                }
            });
        }
        public async void OnGeofenceStateChanged(GeofenceMonitor sender, object e)
        {
            var reports = sender.ReadReports();

            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                foreach (GeofenceStateChangeReport report in reports)
                {
                    GeofenceState state     = report.NewState;
                    Geofence geofence       = report.Geofence;
                    string eventDescription = geofence.Id + " " + DateTime.Now.ToString("T") + " (" + state.ToString();

                    if (state == GeofenceState.Removed)
                    {
                        eventDescription += "/" + report.RemovalReason.ToString() + ")";
                        AddEventDescription(eventDescription);

                        // remove the geofence from the monitor
                        geofenceMonitor.Geofences.Remove(geofence);

                        // Remove the geofence from the list box.
                        foreach (ListBoxItem item in RegisteredGeofenceListBox.Items)
                        {
                            if (item.Tag == geofence)
                            {
                                RegisteredGeofenceListBox.Items.Remove(item);
                                break;
                            }
                        }
                    }
                    else if (state == GeofenceState.Entered || state == GeofenceState.Exited)
                    {
                        // NOTE: You might want to write your app to take particular
                        // action based on whether the app has internet connectivity.

                        eventDescription += ")";
                        AddEventDescription(eventDescription);
                    }
                }
            });
        }
Пример #26
0
        /// <summary>
        /// Inform the user about when entering or exiting the geofence
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void EnterFence(GeofenceMonitor sender, object e)
        {
            var reports = sender.ReadReports();

            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
            {
                foreach (GeofenceStateChangeReport report in reports)
                {
                    GeofenceState state = report.NewState;

                    Geofence geofence = report.Geofence;

                    if (state == GeofenceState.Removed)
                    {
                        GeofenceMonitor.Current.Geofences.Remove(geofence);
                    }
                    else if (state == GeofenceState.Entered)
                    {
                        foreach (Place place in _app.Places)
                        {
                            if (place.Id.ToString() == geofence.Id)
                            {
                                var dia = new MessageDialog("You have entered - " + place.Kind.ToString());
                                await dia.ShowAsync();
                            }
                        }
                    }
                    else if (state == GeofenceState.Exited)
                    {
                        foreach (Place place in _app.Places)
                        {
                            if (place.Id.ToString() == geofence.Id)
                            {
                                var dia = new MessageDialog("You have left - " + place.Kind.ToString());
                                await dia.ShowAsync();
                            }
                        }
                    }
                }
            });
        }
Пример #27
0
        void _monitor_GeofenceStateChanged(GeofenceMonitor sender, object args)
        {
            var fences = sender.ReadReports();

            foreach (var report in fences)
            {
                if (report.Geofence.Id != "Building 9")
                {
                    continue;
                }

                switch (report.NewState)
                {
                case GeofenceState.Entered:
                    Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
                    {
                        MessageDialog dialog = new MessageDialog("Welcome to Building 9, Microsoft Offices");
                        await dialog.ShowAsync();
                    });
                    break;

                case GeofenceState.Exited:
                    Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
                    {
                        MessageDialog dialog = new MessageDialog("Leaving Building 9, Microsoft Offices");

                        await dialog.ShowAsync();
                    });
                    break;

                case GeofenceState.None:
                    break;

                case GeofenceState.Removed:
                    break;

                default:
                    break;
                }
            }
        }
Пример #28
0
        protected void Current_GeofenceStateChanged(GeofenceMonitor sender, object args)
        {
            var reports = sender.ReadReports();

            foreach (var report in reports)
            {
                GeofenceState state = report.NewState;

                Geofence geofence = report.Geofence;

                if (state == GeofenceState.Removed)
                {
                    // remove the geofence from the client side geofences collection
                    this.RemoveGeofence(geofence);
                }
                else if (state == GeofenceState.Entered || state == GeofenceState.Exited)
                {
                    this.PublishGeofence(report.Geoposition, state);
                }
            }
        }
        private async void CurrentOnGeofenceStateChanged(GeofenceMonitor sender, object args)
        {
            var reports = sender.ReadReports();

            await CoreApplication.MainView.Dispatcher.RunAsync(CoreDispatcherPriority.High, agileCallback : (async() =>
            {
                foreach (GeofenceStateChangeReport report in reports)
                {
                    switch (report.NewState)
                    {
                    case GeofenceState.Removed:

                        break;

                    case GeofenceState.Entered:
                        Debug.WriteLine("entered");
                        string username = report.Geofence.Id;
                        CurrentGeofence = report.Geofence;
                        timer.Stop();
                        var packet = new Packet()
                        {
                            PacketType = EPacketType.AllFriendsRequest,
                            Payload =
                                JsonConvert.SerializeObject(new RequestAllFriends()
                            {
                                idList = _user.User.Friends
                            })
                        };

                        TcpClient.DoRequest(packet, GeofenceResponseCallback);
                        break;

                    case GeofenceState.Exited:
                        Debug.WriteLine("kekekekekekekekekekkeke");
                        break;
                    }
                }
            }
                                                                                                             ));
        }
        private void GetGeofenceStateChangedReports()
        {
            GeofenceMonitor monitor      = GeofenceMonitor.Current;
            Geoposition     posLastKnown = monitor.LastKnownGeoposition;

            string geofenceItemEvent = null;

            // Retrieve a vector of state change reports
            var reports = GeofenceMonitor.Current.ReadReports();

            foreach (var report in reports)
            {
                GeofenceState state = report.NewState;
                geofenceItemEvent = report.Geofence.Id;

                if (state == GeofenceState.Removed)
                {
                    GeofenceRemovalReason reason = report.RemovalReason;
                    if (reason == GeofenceRemovalReason.Expired)
                    {
                        geofenceItemEvent += " (Removed/Expired)";
                    }
                    else if (reason == GeofenceRemovalReason.Used)
                    {
                        geofenceItemEvent += " (Removed/Used)";
                    }
                }
                else if (state == GeofenceState.Entered)
                {
                    geofenceItemEvent += " (Entered)";
                }
                else if (state == GeofenceState.Exited)
                {
                    geofenceItemEvent += " (Exited)";
                }
            }
            // NOTE: Other notification mechanisms can be used here, such as Badge and/or Tile updates.
            DoToast(geofenceItemEvent);
        }
Пример #31
0
        public async void OnGeofenceStateChangedHandler(GeofenceMonitor sender, object e)
        {
            bool tagsChanged = false;
            var reports = sender.ReadReports();

          
                foreach (GeofenceStateChangeReport report in reports)
                {
                    GeofenceState state = report.NewState;

                    Geofence geofence = report.Geofence;

                    if (!String.Equals(geofence.Id, triggerFenceName))
                    {

                        if (state == GeofenceState.Removed)
                        {


                        }
                        else if (state == GeofenceState.Entered)
                        {
                            tags.Add(geofence.Id);
                            tagsChanged = true;
                        }
                        else if (state == GeofenceState.Exited)
                        {
                            tags.RemoveAll(x => String.Equals(x, geofence.Id));
                            tagsChanged = true;
                        }
                    }
                }

                if (tagsChanged)
                {
                    await hub.RegisterAsync(GenerateRegistration());
                }
            
        }
        private async void OnGeofenceStateChanged(GeofenceMonitor sender, object args)
        {
            var reports = sender.ReadReports();
            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                foreach (GeofenceStateChangeReport report in reports)
                {
                    GeofenceState state = report.NewState;

                    Geofence geofence = report.Geofence;

                    if (state == GeofenceState.Removed)
                    {
                        // Remove the geofence from the geofences collection.
                        GeofenceMonitor.Current.Geofences.Remove(geofence);
                    }
                    else if (state == GeofenceState.Entered)
                    {
                        // Your app takes action based on the entered event.

                        // NOTE: You might want to write your app to take a particular
                        // action based on whether the app has internet connectivity.
                        System.Diagnostics.Debug.WriteLine("You have entered geofence!");
                        showNotificationPin(report.Geoposition.Coordinate.Point.Position.Latitude, report.Geoposition.Coordinate.Point.Position.Latitude);
                    }
                    else if (state == GeofenceState.Exited)
                    {
                        // Your app takes action based on the exited event.
                        // NOTE: You might want to write your app to take a particular
                        // action based on whether the app has internet connectivity.
                        System.Diagnostics.Debug.WriteLine("You have exited geofence!");
                        if (_dialogsList.Count > 0)
                        {
                            _dialogsList[0].Hide();
                        }
                    }
                }
            });
        }
Пример #33
0
        private void GetGeofenceStateChangedReports()
        {
            GeofenceMonitor monitor = GeofenceMonitor.Current;

            // Registered geofence events can be filtered out if the geofence event time is stale.
            var report = monitor.ReadReports().FirstOrDefault();

            _fence = new Fence()
            {
                Accuracy   = report.Geoposition.Coordinate.Accuracy,
                FenceState = report.NewState,
                Latitude   = report.Geoposition.Coordinate.Point.Position.Latitude,
                Longitude  = report.Geoposition.Coordinate.Point.Position.Longitude,
                TimeStamp  = report.Geoposition.Coordinate.Timestamp
            };
            _fences.Add(_fence);

            if (0 != _fences.Count)
            {
                SaveExistingEvents();
            }
        }
Пример #34
0
        private async void Current_GeofenceStateChanged(GeofenceMonitor sender, object args)
        {
            var Reports = sender.ReadReports();

            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                foreach (GeofenceStateChangeReport report in Reports)
                {
                    GeofenceState state = report.NewState;

                    Geofence geofence = report.Geofence;

                    if (state == GeofenceState.Entered)
                    {
                        ShowMessage("You are pretty close to your room");
                    }
                    else if (state == GeofenceState.Exited)
                    {
                        ShowMessage("You have left pretty far away from your room");
                    }
                }
            });
        }
Пример #35
0
        private async void OnGeofenceStateChanged(GeofenceMonitor sender, object args)
        {
            var reports = sender.ReadReports();

            await CoreApplication.MainView.Dispatcher.RunAsync
                (CoreDispatcherPriority.Normal, () =>
            {
                foreach (GeofenceStateChangeReport report in reports)
                {
                    GeofenceState state = report.NewState;
                    Geofence geofence   = report.Geofence;

                    if (state == GeofenceState.Entered)
                    {
                        GeofenceEnteredEventTriggered?.Invoke(geofence);
                    }
                    else if (state == GeofenceState.Exited)
                    {
                        GeofenceExitedEventTriggered?.Invoke(geofence);
                    }
                }
            });
        }
Пример #36
0
 /// <summary>
 /// Called when geo fence status changes
 /// </summary>
 /// <param name="sender">Sender object</param>
 /// <param name="e">Event arguments</param>
 private async void GeoFence_StatusChanged( GeofenceMonitor sender, object e )
 {
     var reports = sender.ReadReports();
     await Dispatcher.RunAsync( CoreDispatcherPriority.Normal, async () =>
     {
         foreach( GeofenceStateChangeReport report in reports )
         {
             GeofenceState state = report.NewState;
             Geofence geofence = report.Geofence;
             if( state == GeofenceState.Removed )
             {
                 GeofenceMonitor.Current.Geofences.Remove( geofence );
             }
             else if( state == GeofenceState.Entered )
             {
                 foreach( Place place in _app.Places )
                 {
                     if( place.Id.ToString() == geofence.Id )
                     {
                         var dia = new MessageDialog( "You have entered - " + place.Kind.ToString() );
                         await dia.ShowAsync();
                     }
                 }
             }
             else if( state == GeofenceState.Exited )
             {
                 foreach( Place place in _app.Places )
                 {
                     if( place.Id.ToString() == geofence.Id )
                     {
                         var dia = new MessageDialog( "You have left - " + place.Kind.ToString() );
                         await dia.ShowAsync();
                     }
                 }
             }
         }
     } );
 }
Пример #37
0
        void Current_GeofenceStateChanged(GeofenceMonitor sender, object args)
        {
            var reports = sender.ReadReports();
                foreach (GeofenceStateChangeReport report in reports)
                {
                    GeofenceState state = report.NewState;

                    Geofence geofence = report.Geofence;

                    if(state == GeofenceState.Exited)
                    {
                        if(checkIfInGeofence() == false)
                        mapView.setInfoIcon(false);
                    }

                    if (state == GeofenceState.Entered)
                    {

                        mapView.setInfoIcon(true);
                        foreach(Pushpin pin in sightpins.Keys)
                        {
                            if(sightpins[pin].name == geofence.Id)
                            {
                                Sight sight = sightpins[pin];
                                
                                
                                String description = sight.disc;
                                if (Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride == "en")
                                    description = sight.discEng;
                                
                                if (sight.img != "")
                                {
                                    if (sight.img.Length > 3)
                                    {
                                        String[] images = sight.img.Split(',');
                                        mapView.sightFlyout.updateSightInfo(images[0], description, sight.name);
                                        mapView.setInfo();
                                    }
                                    else
                                    {
                                        mapView.sightFlyout.updateSightInfo(sight.img, description, sight.name);
                                        mapView.setInfo();
                                    }
                                }
                                else
                                {
                                    mapView.sightFlyout.updateSightInfo(sight.img, description, sight.name);
                                    mapView.setInfo();
                                }
                                foreach(object o in mapView.getMap().Children)
                                {
                                    if(o.GetType() == typeof(Pushpin))
                                    {
                                        Pushpin p = o as Pushpin;
                                        if(p.Equals(pin))
                                        {
                                            mapView.setPinVisited(p);
                                        }
                                    }

                                }
                            }
                        }
                        
                    }
                }
        }
Пример #38
0
         void _monitor_GeofenceStateChanged(GeofenceMonitor sender, object args)
        {
            
            var fences = sender.ReadReports();
            foreach (var report in fences)
            {
                if (report.Geofence.Id != "Building 9")
                    continue;

                switch (report.NewState)
                {
                    case GeofenceState.Entered:
                        Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
                        {
                            MessageDialog dialog = new MessageDialog("Welcome to Building 9, Microsoft Offices");
                        await dialog.ShowAsync();
                        });
                        break;
                    case GeofenceState.Exited:
                        Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
                        {
                            MessageDialog dialog = new MessageDialog("Leaving Building 9, Microsoft Offices");

                            await dialog.ShowAsync();
                        });
                        break;
                    case GeofenceState.None:
                        break;
                    case GeofenceState.Removed:
                        break;
                    default:
                        break;
                }
            }
        }
Пример #39
0
 private void OnGeofenceStateChanged(GeofenceMonitor sender, object args)
 {
     var reports =
         GeofenceMonitor.Current.ReadReports()
             .Where(report => report.NewState == GeofenceState.Entered)
             .Select(report => report.Geofence.Id);
     ViewModel.OnGeofenceInForeground(reports);
 }
Пример #40
0
        private async void Current_GeofenceStateChanged(GeofenceMonitor sender, object args)
        {
            var Reports = sender.ReadReports();

            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                foreach (GeofenceStateChangeReport report in Reports)
                {
                    GeofenceState state = report.NewState;

                    Geofence geofence = report.Geofence;

                    if (state == GeofenceState.Entered)
                    {
                        ShowMessage("You are pretty close to your room");

                    }
                    else if (state == GeofenceState.Exited)
                    {

                        ShowMessage("You have left pretty far away from your room");
                    }
                }
            });
        }
Пример #41
0
        public async void OnGeofenceStateChanged(GeofenceMonitor sender, object e)
        {
            var reports = sender.ReadReports();

            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                foreach (GeofenceStateChangeReport report in reports)
                {
                    GeofenceState state = report.NewState;

                    Geofence geofence = report.Geofence;

                    if (state == GeofenceState.Removed)
                    {
                        // remove the geofence from the geofences collection
                        GeofenceMonitor.Current.Geofences.Remove(geofence);
                    }
                    else if (state == GeofenceState.Entered)
                    {
                        // Your app takes action based on the entered event

                        // NOTE: You might want to write your app to take particular
                        // action based on whether the app has internet connectivity.
                        foreach(LocationData data in selectedRoute.pubs)
                        {
                            if (data.name.Equals(geofence.Id))
                                geofencePub = data;
                        }

                        if (geofencePub != null)
                        {
                            //string happyhourText = "Happyhour: No";
                            String day = DateTime.Now.DayOfWeek.ToString();
                            PubDay pubday = geofencePub.getDay(day);
                           // if(pubday.happyhour)
                                //happyhourText = "Happyhour: Yes";

                            Summary.Text = "";
                            Hyperlink link = new Hyperlink();
                            link.Inlines.Add(new Run()
                            {
                                Text = geofencePub.name,
                            });
                            Summary.Inlines.Add(new LineBreak());

                            if (isPubOpen(geofencePub))
                            {
                                Summary.Inlines.Add(new Run()
                                {
                                    Text = "Open: yes"
                                });
                            }
                            else
                            {
                                Summary.Inlines.Add(new Run()
                                {
                                    Text = "Open: no",
                                });
                            }
                            Summary.Inlines.Add(link);                               
                        }

                    }
                    else if (state == GeofenceState.Exited)
                    {
                        // Your app takes action based on the exited event

                        // NOTE: You might want to write your app to take particular
                        // action based on whether the app has internet connectivity.
                        visitedPubs = 1;
                        if(visitedPubs < selectedRoute.pubs.Count)
                            getRouteWithCurrentLocation(currentLocation.Point, selectedRoute.pubs[visitedPubs]);
                    }
                }
            });
        }
Пример #42
0
        public void OnGeofenceStateChangedHandler(GeofenceMonitor sender, object e)
        {
            var reports = sender.ReadReports();

            foreach (GeofenceStateChangeReport report in reports)
            {
                GeofenceState state = report.NewState;

                Geofence geofence = report.Geofence;

                
                if (state == GeofenceState.Removed)
                {
                   
                    
                }
                else if (state == GeofenceState.Entered)
                {
                }
                else if (state == GeofenceState.Exited)
                {
                    if(String.Equals(geofence.Id, TriggerFence.Id)){
                        // They have left the area for which we have fences loaded, 
                        // trigger a reload
                        BasicGeoposition current = sender.LastKnownGeoposition.ToBasicGeoposition();
                        RefreshTriggerFence(current);
                        RefreshArmedFences(current);
                    }
                }
            }
        }
Пример #43
0
 private void StatusChanged(GeofenceMonitor sender, object args)
 {
     ;//upsie
 }
 private static void OnGeofenceStateChanged(GeofenceMonitor sender, object e)
 {
     var reports = sender.ReadReports();
     if (Dispatcher != null)
     {
         Dispatcher.BeginInvoke(() =>
         {
             OnGeofenceStateChanged(reports);
         });
     }
     else
     {
         OnGeofenceStateChanged(reports);
     }
 }
        public async void OnGeofenceStatusChanged(GeofenceMonitor sender, object e)
        {
            var status = sender.Status;

            string eventDescription = GetTimeStampedMessage("Geofence Status Changed");

            eventDescription += " (" + status.ToString() + ")";

            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                AddEventDescription(eventDescription);
            });
        }
        public async void OnGeofenceStateChanged(GeofenceMonitor sender, object e)
        {
            var reports = sender.ReadReports();

            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                foreach (GeofenceStateChangeReport report in reports)
                {
                    GeofenceState state = report.NewState;

                    Geofence geofence = report.Geofence;
                    string eventDescription = GetTimeStampedMessage(geofence.Id);

                    eventDescription += " (" + state.ToString();

                    if (state == GeofenceState.Removed)
                    {
                        eventDescription += "/" + report.RemovalReason.ToString() + ")";

                        AddEventDescription(eventDescription);

                        // remove the geofence from the client side geofences collection
                        Remove(geofence);

                        // empty the registered geofence listbox and repopulate
                        geofenceCollection.Clear();

                        FillRegisteredGeofenceListBoxWithExistingGeofences();
                    }
                    else if (state == GeofenceState.Entered || state == GeofenceState.Exited)
                    {
                        // NOTE: You might want to write your app to take particular
                        // action based on whether the app has internet connectivity.

                        eventDescription += ")";

                        AddEventDescription(eventDescription);
                    }
                }
            });
        }
 public GeofenceMonitorEvents(GeofenceMonitor This)
 {
     this.This = This;
 }
Пример #48
0
          public async void OnGeofenceStateChanged(GeofenceMonitor sender, object e)
          {
              var reports = sender.ReadReports();

              await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
              {
                  foreach (GeofenceStateChangeReport report in reports)
                  {
                      GeofenceState state = report.NewState;

                      Geofence geofence = report.Geofence;

                      if (state == GeofenceState.Entered)
                      {
                          try
                          {
                              Waypoint waypoint = GTec.User.Controller.Control.GetInstance().CurrentRoute.WayPoints[int.Parse(geofence.Id)];
                              waypoint.Visited = true;
                              try
                              {
                                  foreach (UIElement element in layer.Children)
                                  {
                                      if (waypoint == null)
                                          continue;

                                      if (waypoint as PointOfInterest == null)
                                          continue;

                                      if((waypoint as PointOfInterest).Name == null)
                                        continue;

                                      if (element == null)
                                          continue;

                                      if (element as Pushpin == null)
                                          continue;

                                      if ((element as Pushpin).Tag == null)
                                          continue;

                                      if(((InfoBoxData)(element as Pushpin).Tag).Title == null)
                                          continue;

                                      if ((((InfoBoxData)(element as Pushpin).Tag)).Title == (waypoint as PointOfInterest).Name)
                                      {
                                          PinTapped(element, new TappedRoutedEventArgs());
                                          break;
                                      }
                                  }
                              }
                              catch
                              {
                                  //YAY
                              }
                          }
                          catch
                          {
                              System.Diagnostics.Debug.WriteLine("Mate, your OnGeofenceStateChanged? It sucks, look at this?! THIS IS CALLED AN EERRRROOORRRR!!!!");
                          }
                          showTraversedRoute();
                          saveTraversedRoute();
                      }
                  }
              });
          }
Пример #49
0
        public async void OnGeofenceStateChanged(GeofenceMonitor sender, object e)
        {
            var reports = sender.ReadReports();

            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                foreach (GeofenceStateChangeReport report in reports)
                {
                    GeofenceState state = report.NewState;

                    Geofence geofence = report.Geofence;

                    if (state == GeofenceState.Removed)
                    {
                        // remove the geofence from the geofences collection
                        GeofenceMonitor.Current.Geofences.Remove(geofence);
                    }
                    else if (state == GeofenceState.Entered)
                    {
                        // Your app takes action based on the entered event

                        // NOTE: You might want to write your app to take particular
                        // action based on whether the app has internet connectivity.
                        LocationData geofenceLocation = null;

                        foreach (LocationData data in routeLocations)
                        {
                            if (data.name.Equals(geofence.Id))
                                geofenceLocation = data;
                        }

                        if(geofenceLocation != null)
                        {
                            Summary.Text = "Geofence entered: " + geofenceLocation.name;
                        }

                    }
                    else if (state == GeofenceState.Exited)
                    {
                        // Your app takes action based on the exited event

                        // NOTE: You might want to write your app to take particular
                        // action based on whether the app has internet connectivity.

                        LocationData geofenceLocation = null;

                        foreach (LocationData data in routeLocations)
                        {
                            if (data.name.Equals(geofence.Id))
                                geofenceLocation = data;
                        }

                        Summary.Text = "Geofence exited: " + geofenceLocation.name;
                        InputMap.Routes.Clear();
                    }
                }
            });
        }
 private void GeofenceStateChanged(GeofenceMonitor sender, object args)
 {
     throw new NotImplementedException();
 }