Ejemplo n.º 1
0
        public static async Task ProcessAsync(string locationArgument, bool verbose)
        {
            if (string.IsNullOrEmpty(API.Configuration.Instance.RequestHeaderFrom))
            {
                UI.PrintFromWarning();
            }

            if (GuessLocationUtils.TryParse(locationArgument, out API.GuessLocationRequest requestLocation))
            {
                var responseLocation = await API.GuessLocation.RunAsync(requestLocation);

                if (responseLocation.IsValid)
                {
                    UI.PrintInfo($"Address: {responseLocation.Address}");
                    UI.PrintInfo($"Coordinates: {responseLocation.Coordinates}");
                    UI.PrintInfo($"https://www.openstreetmap.org/#map={OSM.ZoomLevel}/{responseLocation.Coordinates.Lat}/{responseLocation.Coordinates.Lon}");
                }
                else
                {
                    UI.PrintError("Failed to guess location");
                }
            }
            else
            {
                UI.PrintError($"Invalid argument --{CmdLineAction.Location}");
            }
        }
        private static async Task <(API.GeoPoint coordinates, string address)> GuessBuyerLocationAsync(string locationArgument)
        {
            API.GeoPoint coordinates = null;
            if (!GuessLocationUtils.TryParse(locationArgument, out API.GuessLocationRequest requestLocation))
            {
                coordinates
                    = new API.GeoPoint(
                          double.Parse(API.Configuration.Instance["console:location:longitude"]),
                          double.Parse(API.Configuration.Instance["console:location:latitude"])
                          );
                requestLocation = new API.GuessLocationRequest(coordinates);
            }

            var responseLocation = await API.GuessLocation.RunAsync(requestLocation);

            return(responseLocation.Coordinates ?? coordinates, responseLocation.Address);
        }