Task <List <WowRealmStatusEntry> > CreateRealmUpdateTask(WowSettings.WowRegion region, IEnumerable <CharacterProfile> profiles) { return(Task.Factory.StartNew(() => { try { string url = BuildWowRealmStatusApiUrl(GetUrlForRegion(region), profiles); var request = (HttpWebRequest)WebRequest.Create(url); request.GetResponse(); using (WebResponse response = request.GetResponse()) { using (Stream stream = response.GetResponseStream()) { var serialiser = new DataContractJsonSerializer(typeof(WowRealmStatus)); var result = (WowRealmStatus)serialiser.ReadObject(stream); foreach (var realm in result.Realms) { realm.Region = region; } return result.Realms; } } } catch (Exception ex) { Log.Err(ex.ToString()); return null; } })); }
public WowRealmStatusEntry this[string realm, WowSettings.WowRegion region] { get { lock (_lockObject) { return(Realms.FirstOrDefault(r => r.Name.Equals(realm, StringComparison.InvariantCultureIgnoreCase) && r.Region == region)); } } }
private string GetUrlForRegion(WowSettings.WowRegion region) { switch (region) { case WowSettings.WowRegion.China: return(ChinaWowStatusApiBaseUrl); case WowSettings.WowRegion.EU: return(EuWowStatusApiBaseUrl); case WowSettings.WowRegion.Korea: return(KoreaWowStatusApiBaseUrl); case WowSettings.WowRegion.Taiwan: return(TaiwanWowStatusApiBaseUrl); case WowSettings.WowRegion.US: return(USWowStatusApiBaseUrl); default: return(WowStatusApiBaseUrl); } }
public bool RealmIsOnline(string realm, WowSettings.WowRegion region) { var status = this[realm, region]; return(status != null && status.IsOnline); }
string GetKey(string realm, WowSettings.WowRegion region) { return(string.Format("{0}-{1}", realm.ToUpper(), region)); }