public static bool TryParse(string locationArgument, out API.GuessLocationRequest request) { request = null; // {<lon>;<lat>|<ip>|<address>} if (string.IsNullOrEmpty(locationArgument)) { return(false); } // <lon>;<lat> if (API.GeoPoint.TryParse(locationArgument, out API.GeoPoint location)) { request = new API.GuessLocationRequest(location); return(true); } // <ip> if (IPAddress.TryParse(locationArgument, out IPAddress ip)) { request = new API.GuessLocationRequest(ip); return(true); } // <address> if (locationArgument.Length >= AddressLengthMin) { request = new API.GuessLocationRequest(locationArgument); return(true); } return(false); }
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); }