Beispiel #1
0
        public async Task <GeoIpAnalysisResult> Get(string format, string address)
        {
            this.ValidateAddressInput(address);

            if (string.IsNullOrWhiteSpace(format))
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }

            IDataClient client;

            switch (format.ToLower())
            {
            case "json":
                client = new GeoIpClient <IPApiJsonDataProvider>();
                break;

            case "line":
            default:
                client = new GeoIpClient <IPApiJsonDataProvider>();
                break;
            }

            string data = await client.GetDataAsync($"{address}/json");

            bool isSuccessful = !string.IsNullOrWhiteSpace(data);

            return(new GeoIpAnalysisResult
            {
                IsSuccessful = isSuccessful,
                ResultText = data
            });
        }
Beispiel #2
0
        public async Task GeoIpClinetReturnsDataAsJsonWhenJsonProviderRequested()
        {
            GeoIpClient <IPApiJsonDataProvider> client = new GeoIpClient <IPApiJsonDataProvider>();
            string data = await client.GetDataAsync("8.8.8.8/json");

            Assert.IsFalse(data.Contains(Constants.ERROR_PREFIX));

            try
            {
                _ = JsonConvert.DeserializeObject(data);

                Assert.True(true);
            }
            catch (System.Exception ex)
            {
                Assert.Fail(ex.Message);
            }
        }
        private void GeoIp_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                var geoIpClient = new GeoIpClient();
                var geoIpData   = geoIpClient.GetGeoIpData();
                OptionsViewModel.Latitude  = geoIpData.Latitude.ToString("N7", CultureInfo.InvariantCulture);
                OptionsViewModel.Longitude = geoIpData.Longitude.ToString("N7", CultureInfo.InvariantCulture);

                LatitudeTextBox.Text  = OptionsViewModel.Latitude;
                LongitudeTextBox.Text = OptionsViewModel.Longitude;

                PopupCreator.Success(string.Format(Options.Resources.LocationDetected, geoIpData.City, geoIpData.Country));
            }
            catch
            {
                PopupCreator.Error(Options.Resources.LatLongReceiveError);
            }
        }