public static List <Transaction> GetAllTransactions() { List <Transaction> result = new List <Transaction>(); string looseIssuesDir = GeneralUtils.CheckTransactionsDir(); //get highest year dir string[] yearDirectories = Directory.GetDirectories(looseIssuesDir); if (yearDirectories != null && yearDirectories.Any()) { foreach (string strYear in yearDirectories) { //get highest month dir string[] monthDirectories = Directory.GetDirectories(Path.Combine(looseIssuesDir, strYear)); if (monthDirectories != null && monthDirectories.Any()) { foreach (string strMonth in monthDirectories) { //get all transactions from that dir and get the one with the highest date string[] allTransactionFiles = Directory.GetFiles(Path.Combine(looseIssuesDir, strMonth), "transaction*.json"); try { foreach (string file in allTransactionFiles) { var transaction = GeneralUtils.Load <Transaction>(file); if (transaction != null && transaction.IsValid()) { result.Add(transaction); } } } catch { return(null); } } } } } return(result); }
public static DateTime?GetLaterstTransactionDateFromDisk() { DateTime?highestDateTime = null; string looseIssuesDir = GeneralUtils.CheckTransactionsDir(); //get highest year dir string[] yearDirectories = Directory.GetDirectories(looseIssuesDir); if (yearDirectories != null && yearDirectories.Any()) { List <int> yearDirectoriesInt = new List <int>(); foreach (string strYearFullPath in yearDirectories) { string strYear = Path.GetFileName(strYearFullPath); int intYear; if (int.TryParse(strYear, out intYear)) { yearDirectoriesInt.Add(intYear); } } if (yearDirectoriesInt.Any()) { string highestYear = yearDirectoriesInt.Max().ToString(); //get highest month dir string[] monthDirectories = Directory.GetDirectories(Path.Combine(looseIssuesDir, highestYear)); if (monthDirectories != null && monthDirectories.Any()) { List <int> monthDirectoriesInt = new List <int>(); foreach (string strMonthFullPath in monthDirectories) { string strMonth = Path.GetFileName(strMonthFullPath); int intMonth; if (int.TryParse(strMonth, out intMonth)) { monthDirectoriesInt.Add(intMonth); } } if (monthDirectoriesInt.Any()) { string highestMonth = monthDirectoriesInt.Max().ToString(); //get all transactions from that dir and get the one with the highest date //filenames must start with transaction string[] allTransactionFiles = Directory.GetFiles(Path.Combine(looseIssuesDir, highestYear, highestMonth), "transaction*.json"); try { foreach (string fileFullPath in allTransactionFiles) { var transaction = GeneralUtils.Load <Transaction>(fileFullPath); if (transaction != null && transaction.IsValid()) { if (highestDateTime == null || transaction.CreatedAtLocal > highestDateTime.Value) { highestDateTime = transaction.CreatedAtLocal; } } else { return(null); } } } catch { return(null); } } } } } return(highestDateTime); }