/// <summary> /// Initializes the cache from file. /// </summary> public static void InitializeFromFile() { // Quit if the client has been shut down if (EveMonClient.Closed) { return; } string file = LocalXmlCache.GetFileInfo(Filename).FullName; if (!File.Exists(file) || s_cacheList.Any()) { return; } // Deserialize the file SerializableStationList cache = Util.DeserializeXmlFromFile <SerializableStationList>(file); // Reset the cache if anything went wrong if (cache == null || cache.Stations.Any(x => x.StationID == 0) || cache.Stations.Any(x => x.StationName.Length == 0)) { EveMonClient.Trace("Station and citadel deserialization failed; deleting file."); FileHelper.DeleteFile(file); return; } // Add the data to the cache Import(cache.Stations); }
/// <summary> /// Ensures the importation. /// </summary> private static void EnsureImportation() { // Quit if we already checked a minute ago or query is pending if (s_nextCheckTime > DateTime.UtcNow || s_queryPending) { return; } s_nextCheckTime = DateTime.UtcNow.AddMinutes(1); var info = LocalXmlCache.GetFileInfo(Filename); var result = LocalXmlCache.Load <SerializableNotificationRefTypes>(Filename, true); // Update the file if we don't have it or the data have expired if (result == null || (s_loaded && s_cachedUntil < DateTime.UtcNow)) { Task.WhenAll(UpdateFileAsync()); } else if (!s_loaded) { s_cachedUntil = info.Exists ? info.LastWriteTimeUtc.AddDays(1) : DateTime. MinValue; if (result == null) { s_nextCheckTime = DateTime.UtcNow; } else { // Import the data Import(result); } } }
/// <summary> /// Initializes the cache from file. /// </summary> public static void InitializeFromFile() { // Quit if the client has been shut down if (EveMonClient.Closed) { return; } string file = LocalXmlCache.GetFileInfo(Filename).FullName; if (!File.Exists(file) || s_cacheList.Any()) { return; } // Deserialize the file SerializableEveIDToName cache = Util.DeserializeXmlFromFile <SerializableEveIDToName>(file); // Reset the cache if anything went wrong if (cache == null || cache.Entities.Any(x => x.ID == 0) || cache.Entities.Any(x => x.Name.Length == 0)) { EveMonClient.Trace("Deserializing failed. File may be corrupt. Deleting file."); FileHelper.DeleteFile(file); return; } // Add the data to the cache Import(cache.Entities.Select(entity => new SerializableCharacterNameListItem { ID = entity.ID, Name = entity.Name })); }
/// <summary> /// Ensures the importation. /// </summary> private static void EnsureImportation() { // Quit if we already checked a minute ago or query is pending if (s_nextCheckTime > DateTime.UtcNow || s_queryPending) { return; } s_nextCheckTime = DateTime.UtcNow.AddMinutes(1); string filename = LocalXmlCache.GetFileInfo(Filename).FullName; // Update the file if we don't have it or the data have expired if (!File.Exists(filename) || (s_loaded && s_cachedUntil < DateTime.UtcNow)) { Task.WhenAll(UpdateFileAsync()); return; } // Exit if we have already imported the list if (s_loaded) { return; } s_cachedUntil = File.GetLastWriteTimeUtc(filename).AddDays(1); // Deserialize the xml file CCPAPIResult <SerializableNotificationRefTypes> result = Util. DeserializeAPIResultFromFile <SerializableNotificationRefTypes>(filename, APIProvider.RowsetsTransform); // In case the file has an error we prevent the importation if (result.HasError) { EveMonClient.Trace("Error importing EVE notification types, deleting file"); FileHelper.DeleteFile(filename); s_nextCheckTime = DateTime.UtcNow; return; } // Import the data Import(result.Result); }
/// <summary> /// Ensures the importation. /// </summary> private static void EnsureImportation() { // Quit if we already checked a minute ago or query is pending if (s_nextCheckTime > DateTime.UtcNow || s_queryPending) { return; } s_nextCheckTime = DateTime.UtcNow.AddMinutes(1); string filename = LocalXmlCache.GetFileInfo(Filename).FullName; // Update the file if we don't have it if (!File.Exists(filename)) { Task.WhenAll(UpdateFileAsync()); return; } // Exit if we have already imported the list if (s_isLoaded) { return; } // Deserialize the xml file SerializableEveFlags result = Util.DeserializeXmlFromFile <SerializableEveFlags>(filename, APIProvider.RowsetsTransform); // In case the file has an error we prevent the importation if (result == null) { FileHelper.DeleteFile(filename); s_nextCheckTime = DateTime.UtcNow; return; } // Import the data Import(result); }