public int?GetForecastByZone(int zoneId, TimeSpan timeSpan) { var location = LocationProvider.Instance.GetLocation(ZoneMap[zoneId]); if (location == null) { return(null); } var date = WorldManager.EorzaTime + timeSpan; var localDate = SkywatcherPlugin.EorzeaToLocal(date); var rate = CalculateRate(localDate); var weatherRates = WeatherRateProvider.Instance.GetWeatherRates(location.WeatherRate); if (weatherRates == null) { return(null); } var weatherRate = weatherRates.Rates.FirstOrDefault(r => rate < r.Rate); if (weatherRate == null) { return(null); } return(weatherRate.Weather); }
public int?GetForecastByZone(int zoneId, TimeSpan timeSpan) { int time; var etTillNextInterval = SkywatcherPlugin.GetEorzeaTimeTillNextInterval(); if (timeSpan > etTillNextInterval.Add(TimeSpan.FromHours(8))) { time = 2; } else if (timeSpan > etTillNextInterval) { time = 1; } else { time = 0; } int ff14AnglerZoneId; if (!ZoneMap.TryGetValue(zoneId, out ff14AnglerZoneId)) { return(null); } var weather = weatherResults.FirstOrDefault(s => s.Time == time && s.Area == ff14AnglerZoneId); if (weather != null) { return((int)weather.Weather); } return(null); }
public void Enable() { lock (Locker) { if (!IsEnabled) { IsEnabled = true; RequestTimer.Change(0, (int)SkywatcherPlugin.GetTimeTillNextInterval()); } } }
/// <summary> /// Gets the entries. /// </summary> /// <param name="stateInfo">The state info.</param> private static void GetEntries(object stateInfo) { if (WorldManager.EorzaTime.TimeOfDay.Hours % 8 == 0 || weatherResults == null || lastInterval < SkywatcherPlugin.GetIntervalNumber()) { HttpClient client = null; try { client = new HttpClient(); var response = client.GetContentAsync <WeatherResponse>("http://en.ff14angler.com/skywatcher.php").Result; if (response.Interval > lastInterval) { // Ensure we at least have all of the entries for the current time. if (response.Data.Count(w => w.Time == 0) >= 32 || weatherResults == null) { lastInterval = response.Interval; weatherResults = response.Data; } // If there are 32 or more weather forecasts, shift all weather down an interval. else if (weatherResults.Count(w => w.Time == 1) >= 32) { foreach (var w in weatherResults) { w.Time--; } } } else { // New interval not posted, retry every 30 seconds RequestTimer.Change( TimeSpan.FromSeconds(30), TimeSpan.FromMilliseconds((int)SkywatcherPlugin.GetTimeTillNextInterval())); } } catch (Exception ex) { Logger.Instance.Error(ex.Message); } finally { if (client != null) { client.Dispose(); } } } }