/// <summary> /// Deserialize the file and import the list. /// </summary> private static void Import() { // Exit if we have already imported the list if (s_loaded) { return; } var file = LocalXmlCache.GetFile(s_filename).FullName; // Abort if the file hasn't been obtained for any reason if (!File.Exists(file)) { return; } var result = Util.DeserializeAPIResult <SerializableAPIConquerableStationList>(file, APIProvider.RowsetsTransform); // Checks if EVE Backend Database is temporarily disabled if (result.EVEBackendDatabaseDisabled) { return; } // In case the file has an error we prevent the deserialization if (result.HasError) { return; } // Deserialize the list Import(result.Result.Outposts); }
/// <summary> /// Query this method with the provided HTTP POST data /// </summary> /// <typeparam name="T">The subtype to deserialize (the deserialized type being <see cref="APIResult{T}"/>).</typeparam> /// <param name="method">The method to query</param> /// <param name="postData">The http POST data</param> /// <param name="transform">The XSL transform to apply, may be null.</param> /// <returns>The deserialized object</returns> private APIResult <T> QueryMethod <T>(APIMethods method, HttpPostData postData, XslCompiledTransform transform) { // Download string url = GetMethodUrl(method); var result = Util.DownloadAPIResult <T>(url, postData, transform); // On failure with a custom method, fallback to CCP if (ShouldRetryWithCCP(result)) { return(s_ccpProvider.QueryMethod <T>(method, postData, transform)); } // If the result is a character sheet, we store the result if (method == APIMethods.CharacterSheet && !result.HasError) { SerializableAPICharacterSheet sheet = (SerializableAPICharacterSheet)(Object)result.Result; LocalXmlCache.Save(sheet.Name, result.XmlDocument); } // If the result is a conquerable station list, we store the result if (method == APIMethods.ConquerableStationList && !result.HasError) { LocalXmlCache.Save(method.ToString(), result.XmlDocument); } // Returns return(result); }
/// <summary> /// Asynchrnoneously queries this method with the provided HTTP POST data /// </summary> /// <typeparam name="T">The subtype to deserialize (the deserialized type being <see cref="APIResult{T}"/>).</typeparam> /// <param name="method">The method to query</param> /// <param name="postData">The http POST data</param> /// <param name="callback">The callback to invoke once the query has been completed. It will be done on the data actor (see <see cref="DataObject.CommonActor"/>).</param> /// <param name="transform">The XSL transform to apply, may be null.</param> private void QueryMethodAsync <T>(APIMethods method, HttpPostData postData, XslCompiledTransform transform, QueryCallback <T> callback) { // Check callback not null if (callback == null) { throw new ArgumentNullException("The callback cannot be null.", "callback"); } // Lazy download string url = GetMethodUrl(method); Util.DownloadAPIResultAsync <T>(url, postData, transform, (result) => { // On failure with a custom method, fallback to CCP if (ShouldRetryWithCCP(result)) { result = s_ccpProvider.QueryMethod <T>(method, postData, transform); } // If the result is a character sheet, we store the result if (method == APIMethods.CharacterSheet && !result.HasError) { SerializableAPICharacter sheet = (SerializableAPICharacter)(Object)result.Result; LocalXmlCache.Save(sheet.Name, result.XmlDocument); } // Invokes the callback callback(result); }); }
/// <summary> /// Creates a XML format file for character exportation. /// </summary> /// <param name="character"></param> /// <param name="plan"></param> public static string ExportAsCCPXML(Character character) { // Try to use the last XML character sheet downloaded from CCP var doc = LocalXmlCache.GetCharacterXml(character.Name); if (doc != null) { return(Util.GetXMLStringRepresentation(doc)); } // Displays an error return(null); }
/// <summary> /// Creates the file system paths (settings file name, appdata directory, etc). /// </summary> public static void InitializeFileSystemPaths() { lock (s_pathsInitializationLock) { // Ensure it is made once only if (!String.IsNullOrEmpty(s_settingsFile)) { return; } #if DEBUG s_settingsFile = "settings-debug.xml"; s_traceFile = "trace-debug.txt"; #else s_settingsFile = "settings.xml"; s_traceFile = "trace.txt"; #endif while (true) { try { InitializeEVEMonPaths(); InitializeDefaultEvePortraitCachePath(); LocalXmlCache.Initialize(); return; } catch (UnauthorizedAccessException exc) { string msg = String.Format("An error occurred while EVEMon was looking for its data directory. " + "You may have insufficient rights or a synchronization may be taking place.{0}{0}The message was :{0}{1}", Environment.NewLine, exc.Message); var result = MessageBox.Show( msg, "Couldn't read the data directory", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error); if (result == DialogResult.Cancel) { Application.Exit(); return; } } } } }
/// <summary> /// Downloads the conquerable station list, /// while doing a file up to date check. /// </summary> private static void UpdateList() { // Set the update time and period DateTime updateTime = DateTime.Today.AddHours(EveConstants.DowntimeHour).AddMinutes(EveConstants.DowntimeDuration); TimeSpan updatePeriod = TimeSpan.FromDays(1); // Check to see if file is up to date bool fileUpToDate = LocalXmlCache.CheckFileUpToDate(s_filename, updateTime, updatePeriod); // Up to date ? Quit if (fileUpToDate) { return; } // Query the API var result = EveClient.APIProviders.CurrentProvider.QueryConquerableStationList(); OnUpdated(result); }