/// <summary> /// Performs a request to the TVDB API and returns the resultant object. /// </summary> /// <typeparam name="T">Type of the object to return.</typeparam> /// <param name="url">API sub-URL to use for the request.</param> /// <param name="cacheKey">Key to use for cache storage of this request.</param> /// <param name="ignoreCurrentCache">Ignores existing cache entries for this request.</param> /// <param name="ignorePersistentCache">Does not add this request to the persistent cache.</param> /// <returns>Object returned for the API request.</returns> public T PerformApiRequestAndDeserialize <T>(string url, string cacheKey, bool ignoreCurrentCache = false, bool ignorePersistentCache = false) { Debug.WriteLine("-> TvdbApiRequest::PerformApiRequestAndDeserialize url=\"" + url + "\" cacheKey=\"" + cacheKey + "\" ignoreCurrentCache=\"" + ignoreCurrentCache + "\" ignorePersistentCache=\"" + ignorePersistentCache + "\" Called"); try { // Retreive previous api request from the cache if (CacheProvider.ContainsKey(cacheKey)) { return((T)CacheProvider[cacheKey]); } // Perform api request and deserialize var stream = PerformApiRequest(url); var ser = new XmlSerializer(typeof(T)); var deserialized = (T)ser.Deserialize(stream); // Add to cache if cache is enabled if (CacheProvider.CacheType != TvdbCacheType.None) { CacheProvider.Add(cacheKey, deserialized, ignorePersistentCache); } return(deserialized); } catch (Exception e) { Debug.WriteLine("!> TvdbApiRequest::PerformApiRequestAndDeserialize threw an exception: " + e); return(default(T)); // request probably failed so return null for safe abort } }