public async Task <(string, DarkSkyResponse)> GetWeatherAsync(JToken GeocodeResponse) { var baseUrl = $"https://api.darksky.net/forecast/{ApiKey}/"; var name = GeocodeResponse["display_name"]; if (ApiKey == null) { return(name.ToString(), null); } var lat = GeocodeResponse["lat"]; var lon = GeocodeResponse["lon"]; var httpRequest = new HttpRequestMessage(HttpMethod.Get, Uri.EscapeUriString($"{baseUrl}{lat},{lon}")); httpRequest.Headers.Add("User-Agent", "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)"); httpRequest.Headers.Add("Accept", "application/json"); var darkSkyResponse = await Client.SendAsync(httpRequest); if (!darkSkyResponse.IsSuccessStatusCode) { return(name.ToString(), null); } var response = await darkSkyResponse.Content.ReadAsStringAsync(); var dsr = DarkSkyResponse.FromJson(response); return(name.ToString(), dsr); }
/// <summary> /// Make a request to get forecast data. /// </summary> /// <param name="latitude">Latitude to request data for in decimal degrees.</param> /// <param name="longitude">Longitude to request data for in decimal degrees.</param> /// <param name="parameters">The OptionalParameters to use for the request.</param> /// <returns>A DarkSkyResponse with the API headers and data.</returns> public async Task <DarkSkyResponse> GetForecast(double latitude, double longitude, OptionalParameters parameters = null) { var requestString = BuildRequestUri(latitude, longitude, parameters); var response = await httpClient.HttpRequestAsync($"{baseUri}{requestString}").ConfigureAwait(false); var responseContent = response.Content?.ReadAsStringAsync(); var darkSkyResponse = new DarkSkyResponse { IsSuccessStatus = response.IsSuccessStatusCode, ResponseReasonPhrase = response.ReasonPhrase }; if (!darkSkyResponse.IsSuccessStatus) { return(darkSkyResponse); } try { darkSkyResponse.Response = await jsonSerializerService.DeserializeJsonAsync <Forecast>(responseContent).ConfigureAwait(false); } catch (FormatException e) { darkSkyResponse.Response = null; darkSkyResponse.IsSuccessStatus = false; darkSkyResponse.ResponseReasonPhrase = $"Error parsing results: {e?.InnerException?.Message ?? e.Message}"; } response.Headers.TryGetValues("X-Forecast-API-Calls", out var apiCallsHeader); response.Headers.TryGetValues("X-Response-Time", out var responseTimeHeader); darkSkyResponse.Headers = new ResponseHeaders { CacheControl = response.Headers.CacheControl, ApiCalls = long.TryParse(apiCallsHeader?.FirstOrDefault(), out var callsParsed) ? (long?)callsParsed : null, ResponseTime = responseTimeHeader?.FirstOrDefault() }; if (darkSkyResponse.Response == null) { return(darkSkyResponse); } if (darkSkyResponse.Response.Currently != null) { darkSkyResponse.Response.Currently.TimeZone = darkSkyResponse.Response.TimeZone; } darkSkyResponse.Response.Alerts?.ForEach(a => a.TimeZone = darkSkyResponse.Response.TimeZone); darkSkyResponse.Response.Daily?.Data?.ForEach(d => d.TimeZone = darkSkyResponse.Response.TimeZone); darkSkyResponse.Response.Hourly?.Data?.ForEach(h => h.TimeZone = darkSkyResponse.Response.TimeZone); darkSkyResponse.Response.Minutely?.Data?.ForEach( m => m.TimeZone = darkSkyResponse.Response.TimeZone); return(darkSkyResponse); }
/// <summary> /// Get the request from the forecast API - no json parsing. /// </summary> /// <param name="latitude">Latitude to request data for in decimal degrees.</param> /// <param name="longitude">Longitude to request data for in decimal degrees.</param> /// <param name="parameters">The OptionalParameters to use for the request.</param> /// <returns>A DarkSkyResponse with the API headers and raw response (json).</returns> public async Task <DarkSkyResponse> GetDarkSkyResponse(double latitude, double longitude, OptionalParameters parameters = null) { var requestString = BuildRequestUri(latitude, longitude, parameters); var response = await httpClient.HttpRequest(requestString); var responseContent = await response.Content.ReadAsStringAsync(); var darkSkyResponse = new DarkSkyResponse() { IsSuccessStatus = response.IsSuccessStatusCode, ResponseReasonPhrase = response.ReasonPhrase, RawResponse = responseContent, }; if (darkSkyResponse.IsSuccessStatus) { darkSkyResponse.Response = JsonConvert.DeserializeObject <Forecast>(darkSkyResponse.RawResponse); response.Headers.TryGetValues("X-Forecast-API-Calls", out var apiCallsHeader); response.Headers.TryGetValues("X-Response-Time", out var responseTimeHeader); darkSkyResponse.Headers = new DarkSkyResponse.ResponseHeaders { CacheControl = response.Headers.CacheControl, ApiCalls = long.TryParse(apiCallsHeader?.FirstOrDefault(), out var callsParsed) ? (long?)callsParsed : null, ResponseTime = responseTimeHeader?.FirstOrDefault(), }; } return(darkSkyResponse); }
protected void Build_Click(object sender, EventArgs e) { PropertyInfo property = Application["CurrentProperty"] as PropertyInfo; GeoLocation geoLoc = Application["CurrentGeoLocation"] as GeoLocation; DarkSkySettings settings = Application["CurrentSettings"] as DarkSkySettings; var request = new DarkSkyRequest(); request.DarkSkyRequestAPI = settings.darkSkyApiKey; request.DarkSkyLatitude = geoLoc.Latitude; request.DarkSkyLongitude = geoLoc.Longitude; request.DarkSkyRequestUrl = settings.darkSkyUrl; Application["CurrentRequest"] = request; float buildLatitude = request.DarkSkyLatitude; float buildLongitude = request.DarkSkyLongitude; string apiKey = request.DarkSkyRequestAPI; string baseUrl = request.DarkSkyRequestUrl; string url = string.Format(baseUrl + apiKey + '/' + buildLatitude + ',' + buildLongitude); using (WebClient client = new WebClient()) { string json = client.DownloadString(url); DarkSkyResponse response = (new JavaScriptSerializer().Deserialize <DarkSkyResponse>(json)); Application["CurrentResponse"] = response; Response.Redirect("WeatherTile.aspx"); } }
public async Task AssertInvalidApiKey() { this.forecastParameters.ApiKey = "Invalid API Key"; darkSkyResponse = await weatherRepository.GetForecast(this.forecastParameters); Assert.AreEqual(darkSkyResponse.ResponseReasonPhrase, BadRequest); }
private ForecastResultView getForecastResultView(DarkSkyResponse darkSkyResponse) { var response = darkSkyResponse; var result = new ForecastResultView(); if (response?.Hourly?.Data == null) { return(null); } var averagePressure = Math.Round(response.Hourly.Data.Sum(x => x.Pressure) / response.Hourly.Data.Count, 3); result.AveragePressure = averagePressure; var forecastByDays = response.Hourly.Data.Select(x => new ForecastView { Time = unixTimeStampToDateTime(x.Time), Temperature = x.Temperature, Icon = x.Icon }).ToList(); var resultView = getView(forecastByDays.ToList()); result.AverageTemperatures = resultView.AverageTemperatures; result.RainDays = resultView.RainDays; return(result); }
public void GetWeatherWithRightData() { DarkSkyResponse response = darkSky_.Any(new DarkSkyProject.DarkSky { Location = "bellevue wa" }); Assert.IsNotNull(response.DarkSkyForecastResponse); }
public void GetWeatherLocationNotPassed() { DarkSkyResponse response = darkSky_.Any(new DarkSkyProject.DarkSky { Location = "" }); Assert.AreEqual(response.Message, "Please provide the location"); }
private void MapCurrentForecastToUi(DarkSkyResponse darkSkyResponse) { currentWeather = darkSkyResponse?.Response?.Currently; this.Location.Content = currentWeather.TimeZone; this.ActualTemprature.Content = currentWeather.Temperature.ToDegreeCelsiusWithDegreePostfix(); this.FeelsLikeTemprature.Content = currentWeather.ApparentTemperature.ToDegreeCelsiusWithDegreePostfix(); this.Summary.Content = currentWeather.Summary; this.CloudCover.Content = currentWeather.CloudCover.ToPercentageWithPercentPostfix(); this.WindSpeed.Content = currentWeather.WindSpeed.ToKmPerHrWithKmphPostfix(); this.Humidity.Content = currentWeather.Humidity.ToPercentageWithPercentPostfix(); }
public async Task AssertHasOnlyCurrently() { darkSkyResponse = await weatherRepository.GetForecast(this.forecastParameters); Assert.IsNull(darkSkyResponse.Response.Alerts); Assert.IsNull(darkSkyResponse.Response.Daily); Assert.IsNull(darkSkyResponse.Response.Flags); Assert.IsNull(darkSkyResponse.Response.Hourly); Assert.IsNull(darkSkyResponse.Response.Minutely); Assert.IsNotNull(darkSkyResponse.Response.Currently); }
public async Task <IViewComponentResult> InvokeAsync() { OptionalParameters param = new OptionalParameters(); param.LanguageCode = "tr"; param.MeasurementUnits = "si"; var darkSky = new DarkSky.Services.DarkSkyService("KEY"); DarkSkyResponse forecast = await darkSky.GetForecast(40.1766256, 28.7582773, param); return(View("DarkSkyWidget", forecast)); }
private DarkSkyResponse GetWeather() { DarkSkyResponse result = null; var getWeatherTask = new TaskFactory().StartNew( () => { var client = new DarkSkyService(ApiKey); result = client.GetForecast(this.latitude, this.longitude).Result; }); getWeatherTask.Wait(); return(result); }
private async void SendWeatherInfo(string message) { // Call google to geocode given address, store lat lng for darksky api string geocodeUrl = "https://maps.googleapis.com/maps/api/geocode/json?address=" + message + "&key=" + Config.weatherTokens.googleGeoToken; var geoResponse = await client.GetAsync(geocodeUrl); var geoResponseString = await geoResponse.Content.ReadAsStringAsync(); GeocodeResponse geoFormattedResponse = JsonConvert.DeserializeObject <GeocodeResponse>(geoResponseString); List <Result> result = geoFormattedResponse.results; double lat = result.FirstOrDefault(x => x.geometry.location != null)?.geometry.location.lat ?? 0; double lng = result.FirstOrDefault(x => x.geometry.location != null)?.geometry.location.lng ?? 0; string formattedAddress = result.FirstOrDefault(x => x != null)?.formatted_address ?? ""; // Call DarkSky api with lat lng string darkSkyRequestUrl = "https://api.darksky.net/forecast/" + Config.weatherTokens.darkSkyToken + "/" + lat + "," + lng; var darkResponse = await client.GetAsync(darkSkyRequestUrl); var darkResponseString = await darkResponse.Content.ReadAsStringAsync(); DarkSkyResponse deserializedDarkResponse = JsonConvert.DeserializeObject <DarkSkyResponse>(darkResponseString); //output var emoji = SetEmoji(deserializedDarkResponse.currently.icon); var themeColor = ThemeColor(deserializedDarkResponse.currently.temperature); var embed = new EmbedBuilder(); var annoying = deserializedDarkResponse.currently.cloudCover.ToString("P0", CultureInfo.InvariantCulture); var thing = annoying.Replace(" ", ""); embed.Title = emoji + " " + formattedAddress; embed.WithDescription("" + deserializedDarkResponse.currently.temperature + "F / " + Celcius(deserializedDarkResponse.currently.temperature) + "C\n" + "Cloud Cover: " + deserializedDarkResponse.currently.cloudCover.ToString("P0", CultureInfo.InvariantCulture).Replace(" ", string.Empty) + "\n" + "Windspeed: " + deserializedDarkResponse.currently.windSpeed + "mph\n" + "Humidity: " + deserializedDarkResponse.currently.humidity.ToString("P0", CultureInfo.InvariantCulture).Replace(" ", string.Empty) + "\n" + "Chance of Rain: " + deserializedDarkResponse.daily.data[0].precipProbability.ToString("P0", CultureInfo.InvariantCulture).Replace(" ", string.Empty) + "\n\n" + "Forecast: " + deserializedDarkResponse.daily.summary ); embed.WithColor(themeColor); await Context.Channel.SendMessageAsync("", false, embed); }
protected void Page_Load(object sender, EventArgs e) { PropertyInfo property = Application["CurrentProperty"] as PropertyInfo; GeoLocation geoLoc = Application["CurrentGeoLocation"] as GeoLocation; DarkSkySettings settings = Application["CurrentSettings"] as DarkSkySettings; DarkSkyResponse response = Application["CurrentResponse"] as DarkSkyResponse; if (response.currently.icon != null) { divHotelName.InnerHtml = property.PropertyName; divCity.InnerHtml = property.PropertyCity + "," + " "; divState.InnerHtml = property.PropertyState + " "; divZip.InnerHtml = property.PropertyZipCode.ToString(); divCurrentTemp.InnerHtml = Math.Round(response.currently.temperature).ToString() + "°"; divCurrentDay.InnerHtml = response.currently.time.ToString(); divCurrentDate.InnerHtml = response.currently.time.ToString(); imgCurrentIcon.Alt = response.currently.icon.ToString(); imgDay0Icon.Alt = response.daily.data[0].icon.ToString(); imgDay1Icon.Alt = response.daily.data[1].icon.ToString(); imgDay2Icon.Alt = response.daily.data[2].icon.ToString(); imgDay3Icon.Alt = response.daily.data[3].icon.ToString(); imgDay4Icon.Alt = response.daily.data[4].icon.ToString(); imgDay5Icon.Alt = response.daily.data[5].icon.ToString(); divForecastDay0.InnerHtml = response.daily.data[0].time.ToString(); divForecastDay1.InnerHtml = response.daily.data[1].time.ToString(); divForecastDay2.InnerHtml = response.daily.data[2].time.ToString(); divForecastDay3.InnerHtml = response.daily.data[3].time.ToString(); divForecastDay4.InnerHtml = response.daily.data[4].time.ToString(); divForecastDay5.InnerHtml = response.daily.data[5].time.ToString(); divTemp0.InnerHtml = Math.Round(response.daily.data[0].temperatureMax).ToString() + "°"; divTemp1.InnerHtml = Math.Round(response.daily.data[1].temperatureMax).ToString() + "°"; divTemp2.InnerHtml = Math.Round(response.daily.data[2].temperatureMax).ToString() + "°"; divTemp3.InnerHtml = Math.Round(response.daily.data[3].temperatureMax).ToString() + "°"; divTemp4.InnerHtml = Math.Round(response.daily.data[4].temperatureMax).ToString() + "°"; divTemp5.InnerHtml = Math.Round(response.daily.data[5].temperatureMax).ToString() + "°"; } else { Console.WriteLine("Trouble Connecting to Dark Sky"); } }
/// <summary> /// Requests weather information from dark sky based on the latitude and longitude provided. /// </summary> /// <param name="lat"></param> /// <param name="lon"></param> /// <returns></returns> public async Task <DarkSkyResponse> GetForcast(double lat, double lon) { var requestURL = string.Format("forecast/" + APIKey + "/{0:N4},{1:N4}", lat, lon); HttpRequestMessage message = new HttpRequestMessage(HttpMethod.Get, requestURL); var response = await client.SendAsync(message); var responseContent = await response.Content.ReadAsStringAsync(); // If success continue. if (response.IsSuccessStatusCode) { // Deserialize JSON into DarkSkyResponse object. DarkSkyResponse responseObject = JsonConvert.DeserializeObject <DarkSkyResponse>(responseContent); return(responseObject); } return(null); }
/// <summary> /// Make a request to get forecast data. /// </summary> /// <param name="latitude">Latitude to request data for in decimal degrees.</param> /// <param name="longitude">Longitude to request data for in decimal degrees.</param> /// <param name="parameters">The OptionalParameters to use for the request.</param> /// <returns>A DarkSkyResponse with the API headers and data.</returns> public async Task <DarkSkyResponse> GetForecast(double latitude, double longitude, OptionalParameters parameters = null) { var requestString = BuildRequestUri(latitude, longitude, parameters); var response = await httpClient.HttpRequest(requestString); var responseContent = await response.Content.ReadAsStringAsync(); var darkSkyResponse = new DarkSkyResponse() { IsSuccessStatus = response.IsSuccessStatusCode, ResponseReasonPhrase = response.ReasonPhrase, }; if (darkSkyResponse.IsSuccessStatus) { darkSkyResponse.Response = JsonConvert.DeserializeObject <Forecast>(responseContent); response.Headers.TryGetValues("X-Forecast-API-Calls", out var apiCallsHeader); response.Headers.TryGetValues("X-Response-Time", out var responseTimeHeader); darkSkyResponse.Headers = new DarkSkyResponse.ResponseHeaders { CacheControl = response.Headers.CacheControl, ApiCalls = long.TryParse(apiCallsHeader?.FirstOrDefault(), out var callsParsed) ? (long?)callsParsed : null, ResponseTime = responseTimeHeader?.FirstOrDefault(), }; if (darkSkyResponse.Response != null) { if (darkSkyResponse.Response.Currently != null) { darkSkyResponse.Response.Currently.TimeZone = darkSkyResponse.Response.TimeZone; } darkSkyResponse.Response.Alerts?.ForEach(a => a.TimeZone = darkSkyResponse.Response.TimeZone); darkSkyResponse.Response.Daily?.Data?.ForEach(d => d.TimeZone = darkSkyResponse.Response.TimeZone); darkSkyResponse.Response.Hourly?.Data?.ForEach(h => h.TimeZone = darkSkyResponse.Response.TimeZone); darkSkyResponse.Response.Minutely?.Data?.ForEach(m => m.TimeZone = darkSkyResponse.Response.TimeZone); } } return(darkSkyResponse); }
private void MapAndFormatCurrentForecast(DarkSkyResponse darkSkyResponse) { Loading(false); this.Dispatcher.Invoke(() => { if (!darkSkyResponse.IsSuccessStatus) { if (darkSkyResponse.ResponseReasonPhrase == Forbidden) { MessageBox.Show($"{InvalidInputString}{this.ApiKey.Name}"); } else { MessageBox.Show(SomeErrorText); } return; } MapCurrentForecastToUi(darkSkyResponse); }); }
public WeatherStatus(DarkSkyResponse rawResponse) { this.Summary = rawResponse.Response.Currently.Summary; this.DetailedSummary = rawResponse.Response.Hourly.Summary; this.Temperature = (int)rawResponse.Response.Currently.Temperature; this.IconCode = WeatherDaySummary.GetIconCode(rawResponse.Response.Currently.Icon); this.WindSpeed = (int)rawResponse.Response.Currently.WindSpeed; this.PrecipitationPercentage = (int)(rawResponse.Response.Currently.PrecipProbability * 100); this.HummidityPercentage = (int)(rawResponse.Response.Currently.Humidity * 100); var today = rawResponse.Response.Daily.Data.FirstOrDefault(); if (today != null) { this.SunriseTime = today.SunriseDateTime.Value.DateTime; //Utility.GetDatetimeFromUnix(today.SunriseDateTime); this.SunsetTime = today.SunsetDateTime.Value.DateTime; //Utility.GetDatetimeFromUnix(today.sunsetTime); } this.DailySummary = new List <WeatherDaySummary>(); foreach (var dayItem in rawResponse.Response.Daily.Data) { this.DailySummary.Add(new WeatherDaySummary(dayItem)); } }
public async Task <(List <EmbedBuilder> WeatherResults, List <EmbedBuilder> Alerts)> GetWeatherEmbedsAsync( DarkSkyResponse forecast, GoogleAddress geocode) { if (forecast.IsSuccessStatus) { var alertEmbeds = new List <EmbedBuilder>(); var weatherEmbeds = new List <EmbedBuilder>(); var response = forecast.Response; (string address, string flag) = await GetShortLocationAsync(geocode).ConfigureAwait(false); var hourlyDataPoint = response.Hourly.Data.FirstOrDefault(); if (hourlyDataPoint != null) { var weatherIcons = GetWeatherEmoji(hourlyDataPoint.Icon); var color = CreateWeatherColor(hourlyDataPoint.Temperature); var embed = new EmbedBuilder { Color = color, Title = $"{flag ?? ""}{address}", Description = $"Weather from {hourlyDataPoint.DateTime.Humanize()}", Footer = new EmbedFooterBuilder { Text = "Powered by Dark Sky", IconUrl = "https://darksky.net/images/darkskylogo.png" }, ThumbnailUrl = weatherIcons.Url }.WithCurrentTimestamp(); embed.AddField($"{weatherIcons.Emoji.Name} Summary", response.Hourly.Summary, true); embed.AddField("🌡 Temperature", $"{hourlyDataPoint.Temperature} °C / {hourlyDataPoint.Temperature * 1.8 + 32} °F", true); embed.AddField("☂ Precipitation", string.Format("{0:P1}", hourlyDataPoint.PrecipProbability), true); if (hourlyDataPoint.PrecipIntensity.HasValue && hourlyDataPoint.PrecipIntensity.Value > 0) { embed.AddField("💧 Precipitation Intensity", $"{hourlyDataPoint.PrecipIntensity} (mm/h)", true); } embed.AddField("💧 Humidity", string.Format("{0:P1}", hourlyDataPoint.Humidity), true); embed.AddField("🌬 Wind Speed", $"{hourlyDataPoint.WindSpeed} (m/s)", true); weatherEmbeds.Add(embed); } if (response.Alerts != null) { foreach (var alert in response.Alerts) { var expiration = alert.ExpiresDateTime; string alertContent = alert.Description.Humanize(); if (alertContent.Length >= 512) { alertContent = alertContent.Truncate(512) + "\n\nPlease click on the title for more details."; } var sb = new StringBuilder(); sb.AppendLine(Format.Bold(alert.Title)); sb.AppendLine(); sb.AppendLine(alertContent); sb.AppendLine(); if (expiration > DateTimeOffset.UtcNow) { sb.AppendLine(Format.Italics($"Expires {expiration.Humanize()}")); } var alertEmbed = new EmbedBuilder { Color = Color.DarkOrange, Title = $"Alert for {address}, click me for more details.", Url = alert.Uri.AbsoluteUri, ThumbnailUrl = _config.Icons.Warning, Description = sb.ToString() }; alertEmbeds.Add(alertEmbed); } } return(weatherEmbeds, alertEmbeds); } _loggingService.Log($"Weather returned unexpected response: {forecast.ResponseReasonPhrase}", LogSeverity.Error); return(null, null); }
// only get the data here, buddy public async Task <WeatherRendererInfo> GetForecastAsync(string query) { // use google to get address, lat, and lng for a human-entered string Location location; try { IGeocoder geocoder = new BingMapsGeocoder(bingApiKey); var geoResult = await geocoder.GeocodeAsync(query); dynamic address = geoResult.FirstOrDefault(); if (address == null) { return(null); } location = new Location { Latitude = address.Coordinates.Latitude, Longitude = address.Coordinates.Longitude, FormattedAddress = address.FormattedAddress }; if (address.Type.ToString().StartsWith("Postcode")) { location.FormattedAddress = $"{address.Locality} {address.FormattedAddress}"; } } catch (Exception) { return(null); } // request darksky without minutely/hourly, and use location to determine units var WeatherService = new DarkSkyService(darkSkyApiKey); DarkSkyResponse forecast = await WeatherService.GetForecast(location.Latitude, location.Longitude, new DarkSkyService.OptionalParameters { DataBlocksToExclude = new List <ExclusionBlock> { ExclusionBlock.Minutely, ExclusionBlock.Hourly, }, MeasurementUnits = "auto" }); var timezone = DateTimeZoneProviders.Tzdb[forecast.Response.TimeZone]; var myTime = SystemClock.Instance.GetCurrentInstant(); var info = new WeatherRendererInfo() { Address = location.FormattedAddress, Unit = forecast.Response.Flags.Units == "us" ? "F" : "C", Date = myTime.InZone(timezone), Temperature = forecast.Response.Currently.Temperature, FeelsLike = forecast.Response.Currently.ApparentTemperature, Alert = forecast.Response.Alerts?[0].Title }; int counter = 0; foreach (var day in forecast.Response.Daily.Data.Take(4)) { var dayRender = new WeatherRendererDay() { HiTemp = day.TemperatureHigh, LoTemp = day.TemperatureLow, Summary = weatherDescription.ContainsKey(day.Icon.ToString()) ? weatherDescription[day.Icon.ToString()] : day.Icon.ToString().Replace("-", ""), Icon = string.Join("-", Regex.Split(day.Icon.ToString(), @"(?<!^)(?=[A-Z])")).ToLower(), Date = info.Date.Plus(Duration.FromDays(counter)) }; info.Forecast.Add(dayRender); counter++; } return(info); }
public async Task AssertResponseLocation() { darkSkyResponse = await weatherRepository.GetForecast(this.forecastParameters); Assert.IsTrue(darkSkyResponse.Response.TimeZone.ToLower().Contains("europe")); }
protected void Page_Load(object sender, EventArgs e) { PropertyInfo property = Application["CurrentProperty"] as PropertyInfo; GeoLocation geoLoc = Application["CurrentGeoLocation"] as GeoLocation; DarkSkySettings settings = Application["CurrentSettings"] as DarkSkySettings; DarkSkyResponse response = Application["CurrentResponse"] as DarkSkyResponse; if (response.currently.icon != null) { pic0.AlternateText = response.currently.icon.ToString(); pic00.AlternateText = response.daily.data[0].icon; pic1.AlternateText = response.daily.data[1].icon; pic2.AlternateText = response.daily.data[2].icon; pic3.AlternateText = response.daily.data[3].icon; pic4.AlternateText = response.daily.data[4].icon; pic5.AlternateText = response.daily.data[5].icon; propName.InnerHtml = property.PropertyName; propCity.Text = property.PropertyCity; propState.Text = property.PropertyState; propZip.Text = property.PropertyZipCode.ToString(); currentTemp.Text = Math.Round(response.currently.temperature).ToString() + "°"; divHotelName.InnerHtml = property.PropertyName; divCity.InnerHtml = property.PropertyCity; divState.InnerHtml = property.PropertyState; divZip.InnerHtml = property.PropertyZipCode.ToString(); divCurrentTemp.InnerHtml = Math.Round(response.currently.temperature).ToString() + "°"; day0Day.Text = response.currently.time.ToString(); day0Date.Text = response.currently.time.ToString(); day00.InnerHtml = response.daily.data[0].time.ToString(); day1.InnerHtml = response.daily.data[1].time.ToString(); day2.InnerHtml = response.daily.data[2].time.ToString(); day3.InnerHtml = response.daily.data[3].time.ToString(); day4.InnerHtml = response.daily.data[4].time.ToString(); day5.InnerHtml = response.daily.data[5].time.ToString(); hiTemp0.InnerHtml = Math.Round(response.daily.data[0].temperatureMax).ToString() + "°"; hiTemp1.InnerHtml = Math.Round(response.daily.data[1].temperatureMax).ToString() + "°"; hiTemp2.InnerHtml = Math.Round(response.daily.data[2].temperatureMax).ToString() + "°"; hiTemp3.InnerHtml = Math.Round(response.daily.data[3].temperatureMax).ToString() + "°"; hiTemp4.InnerHtml = Math.Round(response.daily.data[4].temperatureMax).ToString() + "°"; hiTemp5.InnerHtml = Math.Round(response.daily.data[5].temperatureMax).ToString() + "°"; divTemp0.InnerHtml = Math.Round(response.daily.data[0].temperatureMax).ToString() + "°"; divTemp1.InnerHtml = Math.Round(response.daily.data[1].temperatureMax).ToString() + "°"; divTemp2.InnerHtml = Math.Round(response.daily.data[2].temperatureMax).ToString() + "°"; divTemp3.InnerHtml = Math.Round(response.daily.data[3].temperatureMax).ToString() + "°"; divTemp4.InnerHtml = Math.Round(response.daily.data[4].temperatureMax).ToString() + "°"; divTemp5.InnerHtml = Math.Round(response.daily.data[5].temperatureMax).ToString() + "°"; } else { Console.WriteLine("Trouble Connecting to Dark Sky"); } }
public async Task AssertIsStatusSuccess() { darkSkyResponse = await weatherRepository.GetForecast(this.forecastParameters); Assert.AreEqual(darkSkyResponse.IsSuccessStatus, true); }
public async Task AssertIsResponseNull() { darkSkyResponse = await weatherRepository.GetForecast(this.forecastParameters); Assert.IsNotNull(darkSkyResponse); }