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(); } } } }