public void GetEvents() { UpdateInfo updateInfo = null; try { GuildWarsController guildWarsController = new GuildWarsController(); updateInfo = guildWarsController.Update(); } catch (Exception ex) { Console.WriteLine(ex.Message); CouchbaseManager.SetServiceState(false); } finally { if (updateInfo != null) { if (!updateInfo.IsActive) { Console.WriteLine("[{0}] Number of active worlds: {1}.", DateTime.Now, updateInfo.ActiveWorldsCount); } Console.WriteLine(updateInfo.Message); } } }
public UpdateInfo Update() { UpdateInfo updateInfo = new UpdateInfo() { ActiveWorldsCount = 0 , ActiveWorldsUpdates = 0 , Message = string.Format("[{0}] The previous update process is still active. Will try again later.", DateTime.Now) }; ServiceState serviceState = CouchbaseManager.GetServiceState(); if (serviceState.IsActive) { updateInfo.IsActive = serviceState.IsActive; return(updateInfo); } CouchbaseManager.SetServiceState(true); if (_activeWorlds != null) { foreach (World world in _activeWorlds) { //TODO need to make this Asynchronous if (DateTime.Now - world.LastActive < new TimeSpan(0, 0, _minutesBeforeAWorldBecomesInactive, 0)) { string key = CouchbaseKeys.GenerateKeyForWorld(world); bool isStored = CouchbaseManager.Instance.Store( StoreMode.Set , key , _guildWars2ApiHandler.GetEvent(world) ); if (isStored) { updateInfo.ActiveWorldsUpdates++; Console.WriteLine( "[{0}] {1} Updated." , DateTime.Now , key); } updateInfo.ActiveWorldsCount++; } } } updateInfo.Message = string.Format(updateInfo.ActiveWorldsUpdates == 0 ? "[{0}] No updates." : "[{0}] Done with all updates.", DateTime.Now); CouchbaseManager.SetServiceState(false); return(updateInfo); }
public void Stop() { CouchbaseManager.SetServiceState(false); _timer.Stop(); }