public void ParseTest() { #region Test parsing { var metricSystem = new MetricSystem("metricSystemX"); var quantity = new BaseQuantity("quantityX"); var unit = new BaseUnit(metricSystem, quantity, "unitX", "X"); #region Test valid parsing { try { var parsedUnit = Unit.Parse("X"); Assert.AreEqual(unit, parsedUnit, "Valid value should parse into " + "the correct unit."); } catch (Exception e) { Assert.Fail("Valid value parsing should not fail.", e); } } #endregion #region Test invalid parsing //Test invalid parsing { try { Unit.Parse("Z"); Assert.Fail("Invalid value parsing should fail."); } catch (Exception) { } } #endregion } #endregion }
/// <summary> /// Gets by coordinates. /// </summary> /// <typeparam name="T">Generic type parameter.</typeparam> /// <param name="coordinates">The coordinates.</param> /// <param name="metric"> The metric.</param> /// <param name="language"> The language.</param> /// <param name="count"> The count.</param> /// <param name="accuracy"> The accuracy.</param> /// <returns> /// The by coordinates. /// </returns> internal Task <T> GetByCoordinates <T>(Coordinates coordinates, MetricSystem metric, OpenWeatherMapLanguage language, int?count, Accuracy?accuracy) { Ensure.ArgumentNotNull(metric, "metric"); Ensure.ArgumentNotNull(language, "language"); Ensure.ArgumentNotNull(coordinates, "coordinates"); Ensure.ArgumentNotNull(coordinates.Latitude, "coordinates.Latitude"); Ensure.ArgumentNotNull(coordinates.Longitude, "coordinates.Longitude"); this.Request.Parameters.Add("lat", coordinates.Latitude.ToString(CultureInfo.InvariantCulture)); this.Request.Parameters.Add("lon", coordinates.Longitude.ToString(CultureInfo.InvariantCulture)); if (metric != MetricSystem.Internal) { this.Request.Parameters.Add("units", metric.ToString().ToLowerInvariant()); } if (language != OpenWeatherMapLanguage.EN) { this.Request.Parameters.Add("lang", language.ToString().ToLowerInvariant()); } if (count.HasValue) { this.Request.Parameters.Add("cnt", count.Value.ToString(CultureInfo.InvariantCulture)); } if (accuracy.HasValue) { this.Request.Parameters.Add("type", accuracy.Value.ToString().ToLowerInvariant()); } return(this.RunGetRequest <T>()); }
/// <summary> /// Gets by name. /// </summary> /// <typeparam name="T">Generic type parameter.</typeparam> /// <param name="cityName">Name of the city.</param> /// <param name="metric"> The metric.</param> /// <param name="language">The language.</param> /// <param name="count"> The count.</param> /// <param name="accuracy">The accuracy.</param> /// <returns> /// The by name. /// </returns> internal Task <T> GetByName <T>(string cityName, MetricSystem metric, OpenWeatherMapLanguage language, int?count, Accuracy?accuracy) { Ensure.ArgumentNotNullOrEmptyString(cityName, "cityName"); Ensure.ArgumentNotNull(metric, "metric"); Ensure.ArgumentNotNull(language, "language"); this.Request.Parameters.Add("q", cityName.UrlEncode()); if (metric != MetricSystem.Internal) { this.Request.Parameters.Add("units", metric.ToString().ToLowerInvariant()); } if (language != OpenWeatherMapLanguage.EN) { this.Request.Parameters.Add("lang", language.ToString().ToLowerInvariant()); } if (count.HasValue) { this.Request.Parameters.Add("cnt", count.Value.ToString(CultureInfo.InvariantCulture)); } if (accuracy.HasValue) { this.Request.Parameters.Add("type", accuracy.Value.ToString().ToLowerInvariant()); } return(this.RunGetRequest <T>()); }
/// <summary> /// Gets Forecast by city identifier. /// </summary> /// <param name="cityId">The city identifier.</param> /// <param name="daily">if set to <c>true</c> [daily].</param> /// <param name="metric">The metric.</param> /// <param name="language">The language.</param> /// <param name="count">The count.</param> /// <returns>Task{ForecastResponse}.</returns> public Task <ForecastResponse> GetByCityId(int cityId, bool daily = false, MetricSystem metric = MetricSystem.Internal, OpenWeatherMapLanguage language = OpenWeatherMapLanguage.EN, int?count = null) { if (daily) { Request.Uri = Request.Uri.AddSegment("daily"); } return(base.GetByCityId <ForecastResponse>(cityId, metric, language, count)); }
/// <summary> /// Set metric system (default - metric) /// </summary> /// <param name="metricSystem"></param> /// <returns></returns> public async Task <bool> SetMetricSystem(MetricSystem metricSystem) { var characteristic = await Gatt.GetCharacteristicByServiceUuid(MI_BAND_SERVICE, CONFIGURATION_CHARACTERISTIC); byte[] setMetricSystemCmd = new byte[] { 6, 3, 0, (byte)metricSystem }; return(await characteristic.WriteValueAsync(setMetricSystemCmd.ToArray().AsBuffer()) == GattCommunicationStatus.Success); }
/// <summary> /// Gets Forecast by coordinates. /// </summary> /// <param name="coordinates">The coordinates.</param> /// <param name="daily"> if set to <c>true</c> [daily].</param> /// <param name="metric"> The metric.</param> /// <param name="language"> The language.</param> /// <param name="count"> The count.</param> /// <returns> /// Task {ForecastResponse}. /// </returns> /// <seealso cref="M:OpenWeatherMap.IForecastClient.GetByCoordinates(Coordinates,bool,MetricSystem,OpenWeatherMapLanguage,int?)"/> public Task<ForecastResponse> GetByCoordinates(Coordinates coordinates, bool daily = false, MetricSystem metric = MetricSystem.Internal, OpenWeatherMapLanguage language = OpenWeatherMapLanguage.EN, int? count = null) { if (daily) { this.Request.Uri = this.Request.Uri.AddSegment("daily"); } return this.GetByCoordinates<ForecastResponse>(coordinates, metric, language, count, null); }
/// <summary> /// Gets by zip code. /// </summary> /// <typeparam name="T">Generic type parameter.</typeparam> /// <param name="zip">Zip Code for loacation.</param> /// <param name="metric"> The metric.</param> /// <param name="language">The language.</param> /// <param name="count"> The count.</param> /// <param name="accuracy">The accuracy.</param> /// <returns> /// By zip code. /// </returns> public Task <ForecastResponse> GetByZipCode(string zip, bool daily = false, MetricSystem metric = MetricSystem.Internal, OpenWeatherMapLanguage language = OpenWeatherMapLanguage.EN) { if (daily) { this.Request.Uri = this.Request.Uri.AddSegment("daily"); } return(this.GetByZipCode <ForecastResponse>(zip, metric, language, null, null)); }
public void EqualsTest() { #region Test equality comparison { var metricSystem = new MetricSystem("metricSystemX"); var quantity = new BaseQuantity("quantityX"); var baseUnitA = new BaseUnit(metricSystem, quantity, "unitX", "X"); var baseUnitB = new BaseUnit(metricSystem, quantity, "unitY", "Y"); try { #region For base units { #region For equal units { Assert.AreEqual(baseUnitA, baseUnitA, "Equivalent units should test equal."); } #endregion #region For different units { Assert.AreNotEqual(baseUnitA, baseUnitB, "Equivalent units should test equal."); } #endregion } #endregion #region For derived units { var derivedUnitA = baseUnitA * baseUnitA; var derivedUnitB = baseUnitA * baseUnitB; #region For equal units { Assert.AreEqual(derivedUnitA, derivedUnitA, "Equivalent " + "derived units should test equal."); } #endregion #region For different units { Assert.AreNotEqual(derivedUnitA, derivedUnitB, "Equivalent " + "derived units should test equal."); } #endregion } #endregion } catch (Exception e) { if (e is UnitTestAssertException) { throw e; } Assert.Fail("Testing for equality should not fail internally.", e); } } #endregion }
private string MapMetricSystemToQueryParameter(MetricSystem metricSystem) { switch (metricSystem) { case MetricSystem.AUTO: return("units=auto"); case MetricSystem.SI: return("units=si"); case MetricSystem.US: return("units=us"); default: return("units=auto"); } }
public void TryParseTest() { #region Test Parsing { var metricSystem = new MetricSystem("metricSystemX"); var quantity = new BaseQuantity("quantityX"); var unit = new BaseUnit(metricSystem, quantity, "unitX", "X"); try { #region Test valid parsing { Unit parsedUnit; if (Unit.TryParse("X", out parsedUnit)) { Assert.AreEqual(unit, parsedUnit, "Valid value should parse" + " into the correct unit."); } else { Assert.Fail("Valid unit parsing should not fail."); } } #endregion #region Test invalid parsing { Unit parsedUnit; if (Unit.TryParse("Y", out parsedUnit)) { Assert.Fail("Invalid value parsing should fail."); } } } catch (Exception e) { if (e is UnitTestAssertException) { throw e; } Assert.Fail("Parsing should not fail internally.", e); } #endregion } #endregion }
public override int GetHashCode() { int hash = 1; if (ResourceName.Length != 0) { hash ^= ResourceName.GetHashCode(); } if (DistanceBucket != global::Google.Ads.GoogleAds.V10.Enums.DistanceBucketEnum.Types.DistanceBucket.Unspecified) { hash ^= DistanceBucket.GetHashCode(); } if (HasMetricSystem) { hash ^= MetricSystem.GetHashCode(); } if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } return(hash); }
public void CollapseTest() { #region Test unit collapsing { var metricSystem = new MetricSystem("metricSystemX"); var quantity = new BaseQuantity("quantityX"); try { var unit = new BaseUnit(metricSystem, quantity, "unitX", "X"); #region For base unit { var collapsedUnit = unit.Collapse(); Assert.AreEqual(unit, collapsedUnit, "A collapsed base unit " + "should be equal to itself."); } #endregion ; var derivedUnit = unit * unit / unit; #region For derived unit { var collapsedDerivedUnit = derivedUnit.Collapse(); Assert.AreEqual(unit, collapsedDerivedUnit, "A collapsed derived unit " + "X*X/X should result in X."); } #endregion } catch (Exception e) { if (e is UnitTestAssertException) { throw e; } Assert.Fail("Collapsing should not fail internally.", e); } } #endregion }
/// <summary> /// Gets by city identifier. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="cityId">The city identifier.</param> /// <param name="metric">The metric.</param> /// <param name="language">The language.</param> /// <param name="count">The count.</param> /// <returns>Task{``0}.</returns> internal Task <T> GetByCityId <T>(int cityId, MetricSystem metric, OpenWeatherMapLanguage language, int?count) { Ensure.ArgumentNotNull(metric, "metric"); Ensure.ArgumentNotNull(language, "language"); Request.Parameters.Add("id", cityId.ToString(CultureInfo.InvariantCulture)); if (metric != MetricSystem.Internal) { Request.Parameters.Add("units", metric.ToString().ToLowerInvariant()); } if (language != OpenWeatherMapLanguage.EN) { Request.Parameters.Add("lang", language.ToString().ToLowerInvariant()); } if (count.HasValue) { Request.Parameters.Add("cnt", count.Value.ToString(CultureInfo.InvariantCulture)); } return(RunGetRequest <T>()); }
/// <summary> /// Search by coordinates. /// </summary> /// <param name="coordinates">The coordinates.</param> /// <param name="metric"> The metric.</param> /// <param name="language"> The language.</param> /// <param name="count"> The count.</param> /// <param name="accuracy"> The accuracy.</param> /// <returns> /// Task {SearchResponse}. /// </returns> /// <seealso cref="M:OpenWeatherMap.ISearchClient.GetByCoordinates(Coordinates,MetricSystem,OpenWeatherMapLanguage,int?,Accuracy?)"/> public Task<SearchResponse> GetByCoordinates(Coordinates coordinates, MetricSystem metric = MetricSystem.Internal, OpenWeatherMapLanguage language = OpenWeatherMapLanguage.EN, int? count = null, Accuracy? accuracy = null) { return this.GetByCoordinates<SearchResponse>(coordinates, metric, language, count, accuracy); }
/// <summary> /// Gets Current weather by city name. /// </summary> /// <param name="cityName">The city Name.</param> /// <param name="metric"> The metric.</param> /// <param name="language">The language.</param> /// <returns> /// The <see cref="Task"/>. /// </returns> /// <seealso cref="M:OpenWeatherMap.ICurrentWeatherClient.GetByName(string,MetricSystem,OpenWeatherMapLanguage)"/> public Task<CurrentWeatherResponse> GetByName(string cityName, MetricSystem metric = MetricSystem.Internal, OpenWeatherMapLanguage language = OpenWeatherMapLanguage.EN) { return this.GetByName<CurrentWeatherResponse>(cityName, metric, language, null, null); }
/// <summary> /// Gets Current weather by coordinates. /// </summary> /// <param name="coordinates">The coordinates.</param> /// <param name="metric"> The metric system.</param> /// <param name="language"> The language.</param> /// <returns> /// Task {CurrentWeatherResponse}. /// </returns> /// <seealso cref="M:OpenWeatherMap.ICurrentWeatherClient.GetByCoordinates(Coordinates,MetricSystem,OpenWeatherMapLanguage)"/> public Task<CurrentWeatherResponse> GetByCoordinates(Coordinates coordinates, MetricSystem metric = MetricSystem.Internal, OpenWeatherMapLanguage language = OpenWeatherMapLanguage.EN) { return this.GetByCoordinates<CurrentWeatherResponse>(coordinates, metric, language, null, null); }
/// <summary> /// Gets Current weather by city identifier. /// </summary> /// <param name="cityId"> The city identifier.</param> /// <param name="metric"> The metric.</param> /// <param name="language">The language.</param> /// <returns> /// The by city identifier. /// </returns> /// <seealso cref="M:OpenWeatherMap.ICurrentWeatherClient.GetByCityId(int,MetricSystem,OpenWeatherMapLanguage)"/> public Task<CurrentWeatherResponse> GetByCityId(int cityId, MetricSystem metric = MetricSystem.Internal, OpenWeatherMapLanguage language = OpenWeatherMapLanguage.EN) { return this.GetByCityId<CurrentWeatherResponse>(cityId, metric, language, null); }
/// <summary> /// Gets Current weather by coordinates. /// </summary> /// <param name="coordinates">The coordinates.</param> /// <param name="metric"> The metric system.</param> /// <param name="language"> The language.</param> /// <returns> /// Task {CurrentWeatherResponse}. /// </returns> /// <seealso cref="M:OpenWeatherMap.ICurrentWeatherClient.GetByCoordinates(Coordinates,MetricSystem,OpenWeatherMapLanguage)"/> public Task <CurrentWeatherResponse> GetByCoordinates(Coordinates coordinates, MetricSystem metric = MetricSystem.Internal, OpenWeatherMapLanguage language = OpenWeatherMapLanguage.EN) { return(this.GetByCoordinates <CurrentWeatherResponse>(coordinates, metric, language, null, null)); }
public Task<WeatherData> GetByCoordinatesAsync(Coordinates coordinates, MetricSystem metric = MetricSystem.Internal, Language language = Language.EN) { return this.Client.GetByCoordinatesAsync<WeatherData>(coordinates, metric, language); }
/// <summary> /// Search by city name. /// </summary> /// <param name="cityName">Name of the city.</param> /// <param name="metric"> The metric.</param> /// <param name="language">The language.</param> /// <param name="count"> The count.</param> /// <param name="accuracy">The accuracy.</param> /// <returns> /// Task {SearchResponse}. /// </returns> /// <seealso cref="M:OpenWeatherMap.ISearchClient.GetByName(string,MetricSystem,OpenWeatherMapLanguage,int?,Accuracy?)"/> public Task<SearchResponse> GetByName(string cityName, MetricSystem metric = MetricSystem.Internal, OpenWeatherMapLanguage language = OpenWeatherMapLanguage.EN, int? count = null, Accuracy? accuracy = null) { return this.GetByName<SearchResponse>(cityName, metric, language, count, accuracy); }
/// <summary> /// Search by coordinates. /// </summary> /// <param name="coordinates">The coordinates.</param> /// <param name="metric">The metric.</param> /// <param name="language">The language.</param> /// <param name="count">The count.</param> /// <param name="accuracy">The accuracy.</param> /// <returns>Task{SearchResponse}.</returns> public Task <SearchResponse> GetByCoordinates(Coordinates coordinates, MetricSystem metric = MetricSystem.Internal, OpenWeatherMapLanguage language = OpenWeatherMapLanguage.EN, int?count = null, Accuracy?accuracy = null) { return(base.GetByCoordinates <SearchResponse>(coordinates, metric, language, count, accuracy)); }
public Task<ForecastData> GetByNameAsync(string cityName, bool daily = false, MetricSystem metric = MetricSystem.Internal, Language language = Language.EN, int? count = null) { return this.Client.GetByNameAsync<ForecastData>(cityName, metric, language, count, daily); }
public async Task <ForecastResponse> Get(IRequest request, MetricSystem metric = MetricSystem.Internal) { return(await GetForecast($"{_settings.ApiUrl}/forecast?{request.GetQueryString()}&units={metric}&appid={_settings.ApiKey}&mode=json")); }
public Task<ForecastData> GetByCoordinatesAsync(Coordinates coordinates, bool daily = false, MetricSystem metric = MetricSystem.Internal, Language language = Language.EN, int? count = null) { return this.Client.GetByCoordinatesAsync<ForecastData>(coordinates, metric, language, count, daily); }
/// <summary> /// Gets by zip code. /// </summary> /// <typeparam name="T">Generic type parameter.</typeparam> /// <param name="zip">Zip Code for loacation.</param> /// <param name="metric"> The metric.</param> /// <param name="language">The language.</param> /// <param name="count"> The count.</param> /// <param name="accuracy">The accuracy.</param> /// <returns> /// By zip code. /// </returns> public Task <CurrentWeatherResponse> GetByZipCode(string zip, MetricSystem metric = MetricSystem.Internal, OpenWeatherMapLanguage language = OpenWeatherMapLanguage.EN) { return(this.GetByZipCode <CurrentWeatherResponse>(zip, metric, language, null, null)); }
/// <summary> /// Gets Current weather by city identifier. /// </summary> /// <param name="cityId"> The city identifier.</param> /// <param name="metric"> The metric.</param> /// <param name="language">The language.</param> /// <returns> /// The by city identifier. /// </returns> /// <seealso cref="M:OpenWeatherMap.ICurrentWeatherClient.GetByCityId(int,MetricSystem,OpenWeatherMapLanguage)"/> public Task <CurrentWeatherResponse> GetByCityId(int cityId, MetricSystem metric = MetricSystem.Internal, OpenWeatherMapLanguage language = OpenWeatherMapLanguage.EN) { return(this.GetByCityId <CurrentWeatherResponse>(cityId, metric, language, null)); }
public static IPersistedDataAggregator CreateAggregatorForSampleType(MetricSystem.PersistedDataType dataType, string name, DimensionSet dimensionSet, IEnumerable<string> sources, DateTime startTime, DateTime endTime, RecyclableMemoryStreamManager streamManager) { switch (dataType) { case MetricSystem.PersistedDataType.HitCount: return new PersistedDataAggregator<InternalHitCount>(name, dimensionSet, sources, startTime, endTime, streamManager); case MetricSystem.PersistedDataType.VariableEncodedHistogram: return new PersistedDataAggregator<InternalHistogram>(name, dimensionSet, sources, startTime, endTime, streamManager); default: throw new ArgumentException("Invalid data type", "dataType"); } }
public Task<WeatherData> GetByCityIdAsync(int cityId, MetricSystem metric = MetricSystem.Internal, Language language = Language.EN) { return this.Client.GetByCityIdAsync<WeatherData>(cityId, metric, language); }
/// <summary> /// Create an aggregation client for a given data type. /// </summary> /// <param name="dataType">Type of sample to aggregate.</param> /// <param name="name">Name of the data to aggregate.</param> /// <param name="sources">List of source systems to aggregate from.</param> /// <param name="startTime">Start of timespan to aggregate data for.</param> /// <param name="endTime">End of timespan to aggregate data for.</param> /// <param name="streamManager">RecyclableMemoryStreamManager to use when aggregating data.</param> /// <returns>Suitable aggregation client.</returns> public static IPersistedDataAggregator CreateAggregatorForSampleType(MetricSystem.PersistedDataType dataType, string name, IEnumerable<string> sources, DateTime startTime, DateTime endTime, RecyclableMemoryStreamManager streamManager) { return CreateAggregatorForSampleType(dataType, name, null, sources, startTime, endTime, streamManager); }
/// <summary> /// Gets Forecast by coordinates. /// </summary> /// <param name="coordinates">The coordinates.</param> /// <param name="daily"> if set to <c>true</c> [daily].</param> /// <param name="metric"> The metric.</param> /// <param name="language"> The language.</param> /// <param name="count"> The count.</param> /// <returns> /// Task {ForecastResponse}. /// </returns> /// <seealso cref="M:OpenWeatherMap.IForecastClient.GetByCoordinates(Coordinates,bool,MetricSystem,OpenWeatherMapLanguage,int?)"/> public Task <ForecastResponse> GetByCoordinates(Coordinates coordinates, bool daily = false, MetricSystem metric = MetricSystem.Internal, OpenWeatherMapLanguage language = OpenWeatherMapLanguage.EN, int?count = null) { if (daily) { this.Request.Uri = this.Request.Uri.AddSegment("daily"); } return(this.GetByCoordinates <ForecastResponse>(coordinates, metric, language, count, null)); }
public Task<WeatherData> GetByNameAsync(string cityName, MetricSystem metric = MetricSystem.Internal, Language language = Language.EN) { return this.Client.GetByNameAsync<WeatherData>(cityName, metric, language); }
public async Task <ForecastResponse> Get([FromQuery(Name = "q")] string cityName, [FromQuery(Name = "units")] MetricSystem metric) { var result = await _forecastClient.Get(_requestFactory.GetRequest(cityName), metric); if (result.StatusCode != 200) { throw new Exception($"Invalid request {result.StatusCode}"); } return(result); }
public async Task <WeatherDataRoot> GetWeatherDataForCity(City city, ExcludeParameter excludeParameter = ExcludeParameter.AllExceptDailyAndCurrently, MetricSystem metricSystem = MetricSystem.AUTO) { return(await ProcessCityWeatherDataQuery(city, excludeParameter, metricSystem)); }
/// <summary> /// Gets Current weather by city name. /// </summary> /// <param name="cityName">The city Name.</param> /// <param name="metric"> The metric.</param> /// <param name="language">The language.</param> /// <returns> /// The <see cref="Task"/>. /// </returns> /// <seealso cref="M:OpenWeatherMap.ICurrentWeatherClient.GetByName(string,MetricSystem,OpenWeatherMapLanguage)"/> public Task <CurrentWeatherResponse> GetByName(string cityName, MetricSystem metric = MetricSystem.Internal, OpenWeatherMapLanguage language = OpenWeatherMapLanguage.EN) { return(this.GetByName <CurrentWeatherResponse>(cityName, metric, language, null, null)); }
public async Task <IEnumerable <WeatherDataRoot> > GetWeatherDataForMultipleCities(IEnumerable <City> cities, ExcludeParameter excludeParameter = ExcludeParameter.AllExceptDailyAndCurrently, MetricSystem metricSystem = MetricSystem.AUTO) { IList <WeatherDataRoot> weatherDataList = new List <WeatherDataRoot>(); foreach (City city in cities) { WeatherDataRoot weatherDataForCity = await ProcessCityWeatherDataQuery(city, excludeParameter, metricSystem); weatherDataList.Add(weatherDataForCity); } return(weatherDataList.ToArray()); }
private async Task <WeatherDataRoot> ProcessCityWeatherDataQuery(City city, ExcludeParameter excludeParameter, MetricSystem metricSystem) { string relativeUrlWithQueryParams = BuildRelativeCityUrl(ArgumentValidation.ThrowIfNull(city, nameof(city)), excludeParameter, metricSystem); Uri fullUrl; string rawWeatherData; try { fullUrl = new Uri(_darkSkyForecastBaseUrl, relativeUrlWithQueryParams); rawWeatherData = await _weatherDataRetriever.FetchWeatherData(fullUrl); } catch (UriFormatException ex) { Logger.Error("The retrieved DarkSky Forecast Request URL used has invalid format.", ex); throw ex; } catch (HttpRequestException ex) { Logger.Error("The DarkSky Forecast Request failed due to an underlying issue e.g. network connectivity.", ex); throw ex; } catch (ArgumentOutOfRangeException ex) { Logger.Error("The DarkSky Forecast Base URL processing was unsuccessful.", ex); throw ex; } catch (ArgumentNullException ex) { Logger.Error("The DarkSky Forecast Base URL was null.", ex); throw ex; } if (Logger.IsInfoEnabled) { Logger.Info($"Successful weather data retrieval for {city.Name} from URL: {fullUrl}"); } WeatherDataRoot weatherDataForCity; try { weatherDataForCity = ParseWeatherDataFromStringResult(rawWeatherData); } catch (ArgumentNullException ex) { weatherDataForCity = null; Logger.Error("JSON parser had to work on a null raw response.", ex); throw ex; } if (weatherDataForCity != null) { weatherDataForCity.CityName = city.Name; } return(weatherDataForCity); }
private string BuildRelativeCityUrl(City city, ExcludeParameter excludeParameter, MetricSystem metricSystem) { string relativeUrlForCityWithoutQueryParams = city.Latitude + "," + city.Longitude; string excludeQueryParameter = MapExcludeToQueryParameter(excludeParameter); string metricQueryParametere = MapMetricSystemToQueryParameter(metricSystem); return(relativeUrlForCityWithoutQueryParams + "?" + excludeQueryParameter + "&" + metricQueryParametere); }
public async Task <ForecastResponse> Get([FromRoute(Name = "zip")] string zipCode, [FromRoute] string code, [FromQuery(Name = "units")] MetricSystem metric) { var result = await _forecastClient.Get(_requestFactory.GetRequest(zipCode, code), metric); return(result); }
public OpenWeatherMapCatcher() { CultureInfo currentCulture = ServiceRegistration.Get <ILocalization>().CurrentCulture; _dateFormat = currentCulture.DateTimeFormat; _metricSystem = new RegionInfo(currentCulture.Name).IsMetric ? MetricSystem.Metric : MetricSystem.Imperial; if (!Enum.TryParse(currentCulture.TwoLetterISOLanguageName, true, out _language)) { _language = OpenWeatherMapLanguage.EN; } // Start with a random key _keyIndex = new Random(DateTime.Now.Millisecond).Next(KEYS.Length); _settings.SettingsChanged += (sender, args) => ApiToken = _settings.Settings.ApiKey; #region Weather code translation // See https://openweathermap.org/weather-conditions // See https://github.com/ronie/weather.openweathermap.extended/blob/master/resources/lib/utils.py#L118 _weatherCodeTranslation[200] = 4; _weatherCodeTranslation[200] = 4; _weatherCodeTranslation[201] = 4; _weatherCodeTranslation[202] = 3; _weatherCodeTranslation[210] = 4; _weatherCodeTranslation[211] = 4; _weatherCodeTranslation[212] = 3; _weatherCodeTranslation[221] = 38; _weatherCodeTranslation[230] = 4; _weatherCodeTranslation[231] = 4; _weatherCodeTranslation[232] = 4; _weatherCodeTranslation[300] = 9; _weatherCodeTranslation[301] = 9; _weatherCodeTranslation[302] = 9; _weatherCodeTranslation[310] = 9; _weatherCodeTranslation[311] = 9; _weatherCodeTranslation[312] = 9; _weatherCodeTranslation[313] = 9; _weatherCodeTranslation[314] = 9; _weatherCodeTranslation[321] = 9; _weatherCodeTranslation[500] = 11; _weatherCodeTranslation[501] = 11; _weatherCodeTranslation[502] = 11; _weatherCodeTranslation[503] = 11; _weatherCodeTranslation[504] = 11; _weatherCodeTranslation[511] = 11; _weatherCodeTranslation[520] = 11; _weatherCodeTranslation[521] = 11; _weatherCodeTranslation[522] = 11; _weatherCodeTranslation[531] = 40; _weatherCodeTranslation[600] = 14; _weatherCodeTranslation[601] = 16; _weatherCodeTranslation[602] = 41; _weatherCodeTranslation[611] = 18; _weatherCodeTranslation[612] = 6; _weatherCodeTranslation[615] = 5; _weatherCodeTranslation[616] = 5; _weatherCodeTranslation[620] = 14; _weatherCodeTranslation[621] = 46; _weatherCodeTranslation[622] = 43; _weatherCodeTranslation[701] = 20; _weatherCodeTranslation[711] = 22; _weatherCodeTranslation[721] = 21; _weatherCodeTranslation[731] = 19; _weatherCodeTranslation[741] = 20; _weatherCodeTranslation[751] = 19; _weatherCodeTranslation[761] = 19; _weatherCodeTranslation[762] = 19; _weatherCodeTranslation[771] = 2; _weatherCodeTranslation[781] = 0; _weatherCodeTranslation[800] = 32; _weatherCodeTranslation[801] = 34; _weatherCodeTranslation[802] = 30; _weatherCodeTranslation[803] = 30; _weatherCodeTranslation[804] = 28; _weatherCodeTranslation[900] = 0; _weatherCodeTranslation[901] = 1; _weatherCodeTranslation[902] = 2; _weatherCodeTranslation[903] = 25; _weatherCodeTranslation[904] = 36; _weatherCodeTranslation[905] = 24; _weatherCodeTranslation[906] = 17; _weatherCodeTranslation[951] = 33; _weatherCodeTranslation[952] = 24; _weatherCodeTranslation[953] = 24; _weatherCodeTranslation[954] = 24; _weatherCodeTranslation[955] = 24; _weatherCodeTranslation[956] = 24; _weatherCodeTranslation[957] = 23; _weatherCodeTranslation[958] = 23; _weatherCodeTranslation[959] = 23; _weatherCodeTranslation[960] = 4; _weatherCodeTranslation[961] = 3; _weatherCodeTranslation[962] = 2; _weatherCodeTranslationNight[200] = 47; _weatherCodeTranslationNight[201] = 47; _weatherCodeTranslationNight[202] = 47; _weatherCodeTranslationNight[210] = 47; _weatherCodeTranslationNight[211] = 47; _weatherCodeTranslationNight[212] = 47; _weatherCodeTranslationNight[221] = 47; _weatherCodeTranslationNight[230] = 47; _weatherCodeTranslationNight[231] = 47; _weatherCodeTranslationNight[232] = 47; _weatherCodeTranslationNight[300] = 45; _weatherCodeTranslationNight[301] = 45; _weatherCodeTranslationNight[302] = 45; _weatherCodeTranslationNight[310] = 45; _weatherCodeTranslationNight[311] = 45; _weatherCodeTranslationNight[312] = 45; _weatherCodeTranslationNight[313] = 45; _weatherCodeTranslationNight[314] = 45; _weatherCodeTranslationNight[321] = 45; _weatherCodeTranslationNight[500] = 45; _weatherCodeTranslationNight[501] = 45; _weatherCodeTranslationNight[502] = 45; _weatherCodeTranslationNight[503] = 45; _weatherCodeTranslationNight[504] = 45; _weatherCodeTranslationNight[511] = 45; _weatherCodeTranslationNight[520] = 45; _weatherCodeTranslationNight[521] = 45; _weatherCodeTranslationNight[522] = 45; _weatherCodeTranslationNight[531] = 45; _weatherCodeTranslationNight[600] = 46; _weatherCodeTranslationNight[601] = 46; _weatherCodeTranslationNight[602] = 46; _weatherCodeTranslationNight[611] = 46; _weatherCodeTranslationNight[612] = 46; _weatherCodeTranslationNight[615] = 46; _weatherCodeTranslationNight[616] = 46; _weatherCodeTranslationNight[620] = 46; _weatherCodeTranslationNight[621] = 46; _weatherCodeTranslationNight[622] = 46; _weatherCodeTranslationNight[701] = 29; _weatherCodeTranslationNight[711] = 29; _weatherCodeTranslationNight[721] = 29; _weatherCodeTranslationNight[731] = 29; _weatherCodeTranslationNight[741] = 29; _weatherCodeTranslationNight[751] = 29; _weatherCodeTranslationNight[761] = 29; _weatherCodeTranslationNight[762] = 29; _weatherCodeTranslationNight[771] = 29; _weatherCodeTranslationNight[781] = 29; _weatherCodeTranslationNight[800] = 31; _weatherCodeTranslationNight[801] = 33; _weatherCodeTranslationNight[802] = 29; _weatherCodeTranslationNight[803] = 29; _weatherCodeTranslationNight[804] = 27; _weatherCodeTranslationNight[900] = 29; _weatherCodeTranslationNight[901] = 29; _weatherCodeTranslationNight[902] = 27; _weatherCodeTranslationNight[903] = 33; _weatherCodeTranslationNight[904] = 31; _weatherCodeTranslationNight[905] = 27; _weatherCodeTranslationNight[906] = 45; _weatherCodeTranslationNight[951] = 31; _weatherCodeTranslationNight[952] = 31; _weatherCodeTranslationNight[953] = 33; _weatherCodeTranslationNight[954] = 33; _weatherCodeTranslationNight[955] = 29; _weatherCodeTranslationNight[956] = 29; _weatherCodeTranslationNight[957] = 29; _weatherCodeTranslationNight[958] = 27; _weatherCodeTranslationNight[959] = 27; _weatherCodeTranslationNight[960] = 27; _weatherCodeTranslationNight[961] = 45; _weatherCodeTranslationNight[962] = 45; #endregion }
/// <summary> /// Search by city name. /// </summary> /// <param name="cityName">Name of the city.</param> /// <param name="metric">The metric.</param> /// <param name="language">The language.</param> /// <param name="count">The count.</param> /// <param name="accuracy">The accuracy.</param> /// <returns>Task{SearchResponse}.</returns> public Task <SearchResponse> GetByName(string cityName, MetricSystem metric = MetricSystem.Internal, OpenWeatherMapLanguage language = OpenWeatherMapLanguage.EN, int?count = null, Accuracy?accuracy = null) { return(base.GetByName <SearchResponse>(cityName, metric, language, count, accuracy)); }