public async Task <Response <Address> > ToAddressAsync(IGpsLocation gpsLocation)
        {
            if (gpsLocation == null)
            {
                return(_analyticsService.TraceErrorResponse <Address>(this, GeolocationErrors.EmptyLocation));
            }
            try
            {
                var placemarks = await _proxy.GetPlacemarksFromLocationAsync(new Location(gpsLocation.Latitude, gpsLocation.Longitude));

                var bestMatch = placemarks.FirstOrDefault();

                if (bestMatch == null)
                {
                    _analyticsService.TraceWarning(this, "No address found for Gps coordinates", gpsLocation.ToObjectDictionary());
                    return(GeolocationErrors.AddressNotFound.ToResponse <Address>());
                }

                var address = bestMatch.ToAddress();

                _analyticsService.TraceVerbose(this, "Address found from GPS coordinates", gpsLocation.ToObjectDictionary()
                                               .WithValue("Address", address.ToString()));

                return(Response.Success(address));
            }
            catch (Exception e)
            {
                return(_analyticsService.LogExceptionResponse <Address>(this, e, GeolocationErrors.AddressLookupFailed, gpsLocation.ToObjectDictionary("GpsLocation")));
            }
        }
Ejemplo n.º 2
0
 public GeolocationServiceMockBuilder Where_Connect_returns(IGpsLocation location)
 {
     Mock.Setup(x => x.Connect(It.IsAny <GeolocationRequirements>()))
     .Returns(Observable.Create <IGpsLocation>(observer =>
     {
         observer.OnNext(location);
         return(Disposable.Empty);
     }));
     return(this);
 }
 public GeolocationConverterMockBuilder Where_FromAddressAsync_returns(IGpsLocation location, string address = null)
 {
     if (address == null)
     {
         Mock.Setup(x => x.FromAddressAsync(It.IsAny <string>()))
         .ReturnsAsync(Response.Success(location));
     }
     else
     {
         Mock.Setup(x => x.FromAddressAsync(address))
         .ReturnsAsync(Response.Success(location));
     }
     return(this);
 }
Ejemplo n.º 4
0
        public Action <IGpsLocation> Where_Location_returns_and_can_be_updated(IGpsLocation location)
        {
            Mock.Setup(x => x.Connect(It.IsAny <GeolocationRequirements>()))
            .Returns(Observable.Create <IGpsLocation>(observer =>
            {
                void Update(object sender, LocationUpdatedEventArgs args)
                {
                    observer.OnNext(args.NewLocation);
                }

                var updateSubscription = Observable.FromEventPattern <LocationUpdatedEventArgs>(
                    x => UpdateEvent  += Update,
                    x => UpdateEvent  -= Update).Subscribe();

                observer.OnNext(location);

                return(new CompositeDisposable(updateSubscription));
            }));

            return(x => UpdateEvent?.Invoke(this, new LocationUpdatedEventArgs(x)));
        }
Ejemplo n.º 5
0
 public LocationUpdatedEventArgs(IGpsLocation newLocation)
 {
     NewLocation = newLocation;
 }