public static bool GetLatest() { if (latestRatesFromApi == null) { latestRatesFromApi = GetLatestRatesFromApi(); } return(latestRatesFromApi != null); }
private static bool DoesRatesFileExist(ConventerInfo conventerInfo) { var path = GetRatesFilePath(conventerInfo); if (!File.Exists(path)) { return(false); } var fileData = File.ReadAllText(path); return(System.Text.Json.JsonSerializer.Deserialize <ConventerInfo>(fileData) == conventerInfo); }
public static void SaveIntoFile(ConventerInfo conventerInfo) { if (!Directory.Exists(ratesPath)) { try { Directory.CreateDirectory(ratesPath); LogMessage(String.Format("Created directory for files with rates: {0}", Path.GetFullPath(ratesPath))); } catch (Exception ex) { lastErrorMessage = String.Format("Failed creating directory ({0}): {1}", Path.GetFullPath(ratesPath), ex.Message); LogMessage(LastErrorMessage); return; } } var path = GetRatesFilePath(conventerInfo); if (File.Exists(path)) { LogMessage(String.Format("File with rates ({0}) already exists. Overwriting.", Path.GetFullPath(path))); } using (var writer = File.CreateText(path)) { try { writer.Write(System.Text.Json.JsonSerializer.Serialize(conventerInfo)); } catch (Exception ex) { lastErrorMessage = String.Format("Failed saving ({0}): {1}", Path.GetFullPath(path), ex.Message); LogMessage(lastErrorMessage); return; } } LogMessage(String.Format("Saved file with rates: " + Path.GetFullPath(path))); }
private static string GetRatesFilePath(ConventerInfo conventerInfo) { return(Path.Combine(ratesPath, baseCurrency + conventerInfo.date.ToShortDateString() + ".json")); }