/// <summary>
        /// Stop listen to location update / gatherer device location.
        /// </summary>
        private void StopLocationUpdate(GeolocationStatus status)
        {
            if (LocationRetrieveTimer != null)
            {
                // Destroy the timer
                LocationRetrieveTimer.Dispose();
                LocationRetrieveTimer = null;
            }

            if (LocationManager != null)
            {
                // Stop listen to location changes
                LocationManager.StopUpdatingLocation();
                LocationManager.LocationsUpdated -= LocationManager_LocationsUpdated;

                // Remove the reference
                LocationManager = null;
            }

            // Make sure we only update the result if it is not completed yet
            if (LocationTaskCompletionSource != null &&
                !LocationTaskCompletionSource.Task.IsCompleted)
            {
                // Craft the location with all information we have whatever the location is acceptable or not
                var location = IsLastKnownLocationFresh() ?
                               LastKnownLocation.ToNewGeolocation(status) :
                               new Geolocation(status);

                // return the location
                LocationTaskCompletionSource.SetResult(location);
            }
        }
            public async Task SHOULD_publish_last_known_location_and_trace()
            {
                //Act
                Sut.Connect(_requirements)
                .Subscribe(next => { LocationTaskCompletionSource.SetResult(new List <IGpsLocation> {
                        next
                    }); });
                var locations = await LocationTaskCompletionSource.Task;

                //Assert
                Assert.That(locations[0].Latitude, Is.EqualTo(12));
                Assert.That(locations[0].Longitude, Is.EqualTo(22));
                MockAnalyticsService.VerifyTrace("Last known location published");
            }
            public async Task SHOULD_use_given_accuracy(LocationAccuracy given, GeolocationAccuracy required)
            {
                //Arrange
                MockProxy.Where_GetCurrentLocationAsync_returns(new Location(22, 66, DateTimeOffset.Now));

                //Act
                Sut.Connect(new GeolocationRequirements(TimeSpan.FromTicks(1), given))
                .Subscribe(next => { LocationTaskCompletionSource.SetResult(new List <IGpsLocation> {
                        next
                    }); });
                await LocationTaskCompletionSource.Task;

                //Assert
                MockProxy.Mock.Verify(x => x.GetCurrentLocationAsync(It.Is <GeolocationRequest>(y => y.DesiredAccuracy == required)));
            }
            public async Task SHOULD_publish_current_location_and_trace()
            {
                //Act
                Sut.Connect(_requirements)
                .Subscribe(next => { LocationTaskCompletionSource.SetResult(new List <IGpsLocation> {
                        next
                    }); });

                var locations = await LocationTaskCompletionSource.Task;

                //Assert
                Assert.That(locations[0].Latitude, Is.EqualTo(12));
                Assert.That(locations[0].Longitude, Is.EqualTo(22));
                MockAnalyticsService.Mock.Verify(x => x.Debug("Current location published",
                                                              It.IsAny <Dictionary <string, object> >()), Times.Exactly(1));
            }
Ejemplo n.º 5
0
        /// <summary>
        /// Stop listen to location update / gatherer device location.
        /// </summary>
        private void StopLocationUpdate(GeolocationStatus status)
        {
            if (LocationRetrieveTimer != null)
            {
                // Destroy the timer
                LocationRetrieveTimer.Dispose();
                LocationRetrieveTimer = null;
            }

            if (FusedLocationClient != null)
            {
                // Stop listen to location changes
                if (FusedLocationCallback != null)
                {
                    FusedLocationCallback.LocationResult -= FusedLocationCallback_LocationResult;
                    FusedLocationClient.RemoveLocationUpdates(FusedLocationCallback);
                    FusedLocationCallback = null;
                }
                FusedLocationClient.Dispose();
                FusedLocationClient = null;
            }

            if (LocationManager != null)
            {
                // Stop listen to location changes
                LocationManager.RemoveUpdates(this);
                LocationManager.Dispose();
                LocationManager = null;
            }

            // Make sure we only update the result if it is not completed yet
            if (LocationTaskCompletionSource != null &&
                !LocationTaskCompletionSource.Task.IsCompleted)
            {
                // Craft the location with all information we have whatever the location is acceptable or not
                var location = IsLastKnownLocationFresh() ?
                               LastKnownLocation.ToNewGeolocation(status) :
                               new Geolocation(status);

                // return the location
                LocationTaskCompletionSource.SetResult(location);
            }
        }
        /// <summary>
        /// Stop listen to location update / gatherer device location.
        /// </summary>
        private void StopLocationUpdate(GeolocationStatus status)
        {
            if (WindowsGeolocator != null)
            {
                WindowsGeolocator.PositionChanged -= WindowsGeolocator_PositionChanged;
                WindowsGeolocator = null;
            }

            // Make sure we only update the result if it is not completed yet
            if (LocationTaskCompletionSource != null &&
                !LocationTaskCompletionSource.Task.IsCompleted)
            {
                // Craft the location with all information we have whatever the location is acceptable or not
                var location = IsLastKnownLocationFresh() ?
                               LastKnownLocation.ToNewGeolocation(status) :
                               new Geolocation(status);

                // return the location
                LocationTaskCompletionSource.SetResult(location);
            }
        }