Пример #1
0
        public void Outside_Geofence()
        {
            var center = new Position(43.6411314, -79.3808415); // 88 queen's quay
            var current = new Position(43.6515754, -79.3492364); // random point outside fence
            var region = new GeofenceRegion
            {
                Center = center,
                Radius = Distance.FromKilometers(2)
            };

            region
                .IsPositionInside(current)
                .Should()
                .Be(false);
        }
Пример #2
0
        public void Inside_Geofence()
        {
            var current = new Position(43.6429228, -79.3789959); // union station
            var center = new Position(43.6411314, -79.3808415); // 88 queen's quay
            var distance = center.GetDistanceTo(current);

            var region = new GeofenceRegion
            {
                Center = center,
                Identifier = "test",
                Radius = Distance.FromKilometers(3)
            };

            Assert.IsTrue(distance < Distance.FromKilometers(1), "Union station is less than a 1000 meters away");
            region
                .IsPositionInside(current)
                .Should()
                .Be(true, "Union station is inside the 3km geofence from 88 Queen's Quay");
        }
Пример #3
0
        public async Task Test()
        {
            var tcs = new TaskCompletionSource<GeofenceStatusChangedEventArgs>();

            var geofence = new GeofenceRegion
            {
                Identifier = "Test",
                Center = new Position(1.111, 1.111),
                Radius = Distance.FromKilometers(1)
            };
            var locator = new Mock<IGeolocator>();
            locator
                .Setup(x => x.StartListeningAsync(It.IsAny<int>(), It.IsAny<double>(), false))
                .Returns(() => Task.FromResult(true));

            var mgr = new GeofenceManagerImpl(locator.Object, new GeofenceSettings
            {
                MonitoredRegions = new List<GeofenceRegion>(new [] { geofence })
            });
            mgr.RegionStatusChanged += (sender, args) => tcs.SetResult(args);

            // first raise establishes current status, must do twice
            locator.Raise(
                x => x.PositionChanged += null,
                new PositionEventArgs(new Plugin.Geolocator.Abstractions.Position
                {
                    Latitude = geofence.Center.Latitude,
                    Longitude = geofence.Center.Longitude
                })
            );

            var result = await tcs.Task;

            result.Status.Should().Be(GeofenceStatus.Exited);
            result.Region.Identifier.Should().Be(geofence.Identifier);
        }
Пример #4
0
 public Task StopMonitoring(GeofenceRegion region)
 {
     this.regions.Remove(region);
     return(Task.CompletedTask);
 }
Пример #5
0
 public Task StartMonitoring(GeofenceRegion region)
 {
     this.regions.Add(region);
     return(Task.CompletedTask);
 }
Пример #6
0
 public abstract Task <GeofenceState> RequestState(GeofenceRegion region, CancellationToken cancelToken = default);
Пример #7
0
 public abstract Task StartMonitoring(GeofenceRegion region);
Пример #8
0
 public Task OnStatusChanged(GeofenceState newStatus, GeofenceRegion region)
 {
     return(Task.CompletedTask);
 }
Пример #9
0
 public async Task OnStatusChanged(GeofenceState newStatus, GeofenceRegion region)
 {
     //Aqui voce Pode implementar um Delegate pra Geofence
 }
Пример #10
0
        protected override void OnStart()
        {
            AppCenter.Start("ios=c9f5ef06-26e7-4e66-8f7f-d122adb66eff;" +
                            "android=c9f5ef06-26e7-4e66-8f7f-d122adb66eff",
                            typeof(Analytics), typeof(Crashes));

            // Start monitoring all locations
            var locatieController = App.container.Resolve <IEntityController <Locatie> >();
            var locaties          = locatieController.Get();

            CrossGeofences.Current.StopAllMonitoring();
            foreach (var locatie in locaties)
            {
                var region = new GeofenceRegion(
                    locatie.Id.ToString(),
                    new Position(locatie.Latitude, locatie.Longitude),
                    Distance.FromKilometers(locatie.Radius)
                    );

                CrossGeofences.Current.StartMonitoring(region);
            }

            CrossGeofences.Current.RegionStatusChanged += (sender, args) =>
            {
                var locatie = locatieController.Get().Where(l => l.Id.ToString() == args.Region.Identifier);
                var registratieController = App.container.Resolve <IEntityController <Registratie> >();

                switch (args.Status)
                {
                case GeofenceStatus.Unknown:
                    break;

                case GeofenceStatus.Entered:
                    registratieController.Add(new Model.Registratie()
                    {
                        LocatieID      = int.Parse(args.Region.Identifier),
                        StartTijd      = DateTime.Now,
                        GPSRegistratie = true
                    });

                    break;

                case GeofenceStatus.Exited:
                    var activeRegistration = registratieController.Get()
                                             .Where(x => x.LocatieID.ToString() == args.Region.Identifier)
                                             .FirstOrDefault(x => x.EindTijd == null);

                    if (activeRegistration == null)
                    {
                        // TODO zou niet moeten kunnen, netjes fixen
                        break;
                    }

                    activeRegistration.EindTijd = DateTime.Now;
                    registratieController.Update(activeRegistration);
                    break;

                default:
                    break;
                }
            };
        }
Пример #11
0
 public static Task StartMonitoring(GeofenceRegion region) => Current.StartMonitoring(region);
Пример #12
0
 public static Task <GeofenceState> RequestState(GeofenceRegion region, CancellationToken cancelToken = default)
 => Current.RequestState(region, cancelToken);
Пример #13
0
 public Task OnStatusChanged(GeofenceState newStatus, GeofenceRegion region)
 {
     throw new NotImplementedException();
 }
Пример #14
0
 public Task OnStatusChanged(GeofenceState newStatus, GeofenceRegion region) => Task.CompletedTask;
Пример #15
0
 public void OnStatusChanged(GeofenceState newStatus, GeofenceRegion region)
 {
 }