WeatherData weatherData = null;
// Check to see if the key for the application state data is in the State dictionary.
- string JSONRemoteForecastWeather = null;
- string JSONRemoteCurrentWeather = null;
+ string jsonForecast = null;
+ string jsonCurrent = null;
string city = null;
string country = null;
- if (PhoneApplicationService.Current.State.ContainsKey("JSONRemoteForecastWeather") &&
- PhoneApplicationService.Current.State.ContainsKey("JSONRemoteCurrentWeather") &&
+ if (PhoneApplicationService.Current.State.ContainsKey("JSONForecast") &&
+ PhoneApplicationService.Current.State.ContainsKey("JSONCurrent") &&
PhoneApplicationService.Current.State.ContainsKey("City") &&
PhoneApplicationService.Current.State.ContainsKey("Country"))
{
// If it exists, assign the data to the application member variable.
- JSONRemoteForecastWeather = PhoneApplicationService.Current.State["JSONRemoteForecastWeather"] as string;
+ jsonForecast = PhoneApplicationService.Current.State["JSONForecast"] as string;
// If it exists, assign the data to the application member variable.
- JSONRemoteCurrentWeather = PhoneApplicationService.Current.State["JSONRemoteCurrentWeather"] as string;
+ jsonCurrent = PhoneApplicationService.Current.State["JSONCurrent"] as string;
// If it exists, assign the data to the application member variable.
city = PhoneApplicationService.Current.State["City"] as string;
// If it exists, assign the data to the application member variable.
country = PhoneApplicationService.Current.State["Country"] as string;
}
-
- if (!string.IsNullOrEmpty(JSONRemoteCurrentWeather) && !string.IsNullOrEmpty(JSONRemoteForecastWeather) &&
+
+ if (!string.IsNullOrEmpty(jsonCurrent) && !string.IsNullOrEmpty(jsonForecast) &&
!string.IsNullOrEmpty(city) && !string.IsNullOrEmpty(country))
{
var parser = new ServiceParser(new JsonParser());
- weatherData = parser.WeatherDataParser(JSONRemoteForecastWeather, JSONRemoteCurrentWeather);
- weatherData.City = city;
- weatherData.Country = country;
+ weatherData = parser.WeatherDataParser(jsonForecast, jsonCurrent, city, country);
}
ApplicationDataObject = weatherData;
var weatherData = ApplicationDataObject;
if (weatherData != null)
{
- if (!string.IsNullOrEmpty(weatherData.JSONRemoteCurrent) &&
- !string.IsNullOrEmpty(weatherData.JSONRemoteForecast))
+ if (!string.IsNullOrEmpty(weatherData.JSONCurrent) &&
+ !string.IsNullOrEmpty(weatherData.JSONForecast))
{
// Store it in the State dictionary.
- PhoneApplicationService.Current.State["JSONRemoteForecastWeather"] = weatherData.JSONRemoteForecast;
+ PhoneApplicationService.Current.State["JSONForecast"] = weatherData.JSONForecast;
// Store it in the State dictionary.
- PhoneApplicationService.Current.State["JSONRemoteCurrentWeather"] = weatherData.JSONRemoteCurrent;
+ PhoneApplicationService.Current.State["JSONCurrent"] = weatherData.JSONCurrent;
// Store it in the State dictionary.
PhoneApplicationService.Current.State["City"] = weatherData.City;
// Gets the data from the web.
(Application.Current as WeatherInformation.App).ApplicationDataObject =
- await GetRemoteDataAsync(locationItem).ConfigureAwait(false);
+ await GetRemoteDataAsync(locationItem);
using (var db = new LocationDataContext(LocationDataContext.DBConnectionString))
{
}
// Call UpdateUI on the UI thread.
- Dispatcher.BeginInvoke(() => UpdateUI());
+ // Without ConfigureAwait(false) await returns data on the calling thread. In this case the calling one
+ // is the UI thread. So, I can save the call to Dispatcher.BeginInvoke.
+ //Dispatcher.BeginInvoke(() => UpdateUI());
+ UpdateUI();
}
void UpdateUI()
string formattedForecastURL = String.Format(
CultureInfo.InvariantCulture, AppResources.URIAPIOpenWeatherMapForecast,
AppResources.APIVersionOpenWeatherMap, latitude, longitude, resultsNumber);
- string JSONRemoteForecastWeather = await httpClient.GetWeatherDataAsync(formattedForecastURL).ConfigureAwait(false);
+ string jsonForecast = await httpClient.GetWeatherDataAsync(formattedForecastURL).ConfigureAwait(false);
string formattedCurrentURL = String.Format(
CultureInfo.InvariantCulture, AppResources.URIAPIOpenWeatherMapCurrent,
AppResources.APIVersionOpenWeatherMap, latitude, longitude, resultsNumber);
- string JSONRemoteCurrentWeather = await httpClient.GetWeatherDataAsync(formattedCurrentURL).ConfigureAwait(false);
+ string jsonCurrent = await httpClient.GetWeatherDataAsync(formattedCurrentURL).ConfigureAwait(false);
var parser = new ServiceParser(new JsonParser());
- var weatherData = parser.WeatherDataParser(JSONRemoteForecastWeather, JSONRemoteCurrentWeather);
- weatherData.City = locationItem.City;
- weatherData.Country = locationItem.Country;
+ var weatherData = parser.WeatherDataParser(jsonForecast, jsonCurrent, locationItem.City, locationItem.Country);
return weatherData;
}
return this._jsonParser.ParserWeatherData<ForecastWeather>(jsonData);
}
- public WeatherData WeatherDataParser(string JSONRemoteForecastWeather, string JSONRemoteCurrentWeather)
+ public WeatherData WeatherDataParser(
+ string JSONForecast, string JSONCurrent, string city, string country)
{
- if (string.IsNullOrEmpty(JSONRemoteForecastWeather))
+ if (string.IsNullOrEmpty(JSONForecast))
{
- throw new ArgumentException("Missing argument", "JSONRemoteForecastWeather");
+ throw new ArgumentException("Missing argument", "JSONForecast");
}
- if (string.IsNullOrEmpty(JSONRemoteCurrentWeather))
+ if (string.IsNullOrEmpty(JSONCurrent))
{
- throw new ArgumentException("Missing argument", "JSONRemoteCurrentWeather");
+ throw new ArgumentException("Missing argument", "JSONCurrent");
}
- return new WeatherData
- {
- JSONRemoteCurrent = JSONRemoteCurrentWeather,
- JSONRemoteForecast = JSONRemoteForecastWeather,
- RemoteCurrent = GetCurrentWeather(JSONRemoteCurrentWeather),
- RemoteForecast = GetForecastWeather(JSONRemoteForecastWeather),
- };
+ var forecast = GetForecastWeather(JSONForecast);
+ var current = GetCurrentWeather(JSONCurrent);
+ return new WeatherData(forecast, JSONForecast, current, JSONCurrent, city, country);
}
}
}
{
public class WeatherData
{
- public ForecastWeather RemoteForecast
- {
- get;
- set;
- }
- public string JSONRemoteForecast
- {
- get;
- set;
- }
+ private readonly ForecastWeather _forecast;
+ private readonly string _jsonForecast;
+ private readonly CurrentWeather _current;
+ private readonly string _jsonCurrent;
+ private readonly string _city;
+ private readonly string _country;
-
- public CurrentWeather RemoteCurrent
- {
- get;
- set;
- }
- public string JSONRemoteCurrent
+ public WeatherData(ForecastWeather forecast, string jsonForecast, CurrentWeather current,
+ string jsonCurrent, string city, string country)
{
- get;
- set;
+ _forecast = forecast;
+ _jsonForecast = jsonForecast;
+ _current = current;
+ _jsonCurrent = jsonCurrent;
+ _city = city;
+ _country = country;
}
- public string City { get; set;}
-
- public string Country { get; set; }
+ public ForecastWeather Forecast { get { return _forecast; } }
+ public string JSONForecast { get { return _jsonForecast; } }
+ public CurrentWeather Current { get { return _current; } }
+ public string JSONCurrent { get { return _jsonCurrent; } }
+ public string City { get { return _city; } }
+ public string Country { get { return _country; } }
}
}
shell:SystemTray.IsVisible="True"
d:DataContext="{d:DesignData /SampleData/SelectedDateViewModelSampleData.xaml}">
- <phone:PhoneApplicationPage.Resources>
- <ViewModels:SelectedDateViewModel x:Key="SelectedDateViewModelDataSource" d:IsDataSource="True"/>
- </phone:PhoneApplicationPage.Resources>
<phone:PhoneApplicationPage.FontFamily>
<StaticResource ResourceKey="PhoneFontFamilyNormal"/>
</phone:PhoneApplicationPage.FontFamily>
string symbol = isFahrenheit ? AppResources.TemperatureUnitsFahrenheitSymbol : AppResources.TemperatureUnitsCentigradeSymbol;
DateTime unixTime = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
- var remoteForecastWeatherData = weatherData.RemoteForecast;
+ var remoteForecastWeatherData = weatherData.Forecast;
if (remoteForecastWeatherData != null)
{
this.ForecastItems.Clear();
// TODO: nullables?
// TODO: nullables para distinguir cuando hay datos o no. Ahora me llega 0 si no datos (supongo) cuando double/integer
- var remoteCurrentWeatherData = weatherData.RemoteCurrent;
+ var remoteCurrentWeatherData = weatherData.Current;
if (remoteCurrentWeatherData != null)
{
string weatherImage;
public void LoadData(WeatherData weatherData, int index)
{
- var remoteForecastWeatherData = weatherData.RemoteForecast;
+ var remoteForecastWeatherData = weatherData.Forecast;
WeatherInformation.Model.ForecastWeatherParser.List forecast = remoteForecastWeatherData.list[index];
DateTime unixTime = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);