public static CacheResult QueryApi(string apiPath, IDictionary<string, string> parameters) { string cachePath = GetCachePath(apiPath, parameters); ICacheStrategy cacheStrategy = new EveApiCacheStrategy(); // query the API return Resources.CacheFilePost(new Uri(m_apiRoot, apiPath).ToString(), cachePath, cacheStrategy, parameters, delegate(string tempPath) { // inspect the resulting file for errors using (FileStream tempStream = File.Open(tempPath, FileMode.Open, FileAccess.Read)) { XPathDocument doc = new XPathDocument(tempStream); XPathNavigator nav = doc.CreateNavigator(); XPathNavigator errorNode = nav.SelectSingleNode("/eveapi/error"); // check if there was an error node if (errorNode != null) throw new EveApiException(errorNode.SelectSingleNode("@code").ValueAsInt, errorNode.Value); // now check if there appears to at least be an eveapi node if (nav.SelectSingleNode("/eveapi") == null) throw new EveApiException(0, "No valid eveapi XML found in response."); } }); }
/// <summary> /// Gets the current cache status of an API query. /// </summary> /// <param name="apiPath">the API URL relative to the API root</param> /// <param name="parameters">the API parameters</param> public static CacheResult CheckApi(string apiPath, IDictionary<string, string> parameters) { string cachePath = GetCachePath(apiPath, parameters); ICacheStrategy cacheStrategy = new EveApiCacheStrategy(); return Resources.IsFileCached(cachePath, cacheStrategy); }