public MainPage() { this.InitializeComponent(); ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.FullScreen; movies = new List<Movie>(); lastDownloaded = DateTime.MinValue; haveNotPulled = true; lastTimeCheck = DateTime.MinValue; cachedTimeOfDay = Movie.TimesOfDay.Unknown; sunrise = DateTime.MinValue; sunset = DateTime.MinValue; }
public async Task<Movie.TimesOfDay> GetTimeOfDay() { if (haveNotPulled) { HttpClient client = new HttpClient(); HttpResponseMessage response = await client.GetAsync(string.Format("http://api.wunderground.com/api/{0}/astronomy/q/autoip.json", Secrets.ApiKey)); haveNotPulled = false; JObject o = null; try { o = JObject.Parse(await response.Content.ReadAsStringAsync()); sunrise = DateTimeHelper(int.Parse((string)o["moon_phase"]["sunrise"]["hour"]), int.Parse((string)o["moon_phase"]["sunrise"]["minute"])); sunset = DateTimeHelper(int.Parse((string)o["moon_phase"]["sunset"]["hour"]), int.Parse((string)o["moon_phase"]["sunset"]["minute"])); DateTime now = DateTime.Now; if (sunrise < now && now < sunset) { cachedTimeOfDay = Movie.TimesOfDay.Day; } else { cachedTimeOfDay = Movie.TimesOfDay.Night; } return cachedTimeOfDay; } catch { cachedTimeOfDay = Movie.TimesOfDay.Day; return cachedTimeOfDay; } } else { DateTime now = DateTime.Now; if (sunrise < now && now < sunset) { cachedTimeOfDay = Movie.TimesOfDay.Day; } else { cachedTimeOfDay = Movie.TimesOfDay.Night; } return cachedTimeOfDay; } }