public static ReadFileContent ( string filename, string foldername ) : Task |
||
filename | string | the name of the file |
foldername | string | the name of the folder containing the file |
Результат | Task |
/// <summary> /// Adds report to the stored report list /// </summary> /// <param name="report">the DriveReport to be added to the list</param> /// <returns>true on success, false on failure</returns> public static async Task <bool> AddReportToList(DriveReport report) { try { var content = await FileHandler.ReadFileContent(Definitions.ReportsFileName, Definitions.ReportsFolderName); var list = JsonConvert.DeserializeObject <List <DriveReport> >(content); if (list == null) { list = new List <DriveReport>(); } list.Add(report); var toBeWritten = JsonConvert.SerializeObject(list); var test = await FileHandler.WriteFileContent(Definitions.ReportsFileName, Definitions.ReportsFolderName, toBeWritten); if (test) { Definitions.storedReportsCount = list.Count; } return(test); } catch (Exception e) { return(false); } }
/// <summary> /// Gets the amount of stored reports /// </summary> /// <returns>integer representing the amount of stored reports</returns> public static async Task GetCount() { try { var content = await FileHandler.ReadFileContent(Definitions.ReportsFileName, Definitions.ReportsFolderName); var list = JsonConvert.DeserializeObject <List <DriveReport> >(content); Definitions.storedReportsCount = list.Count; } catch (Exception e) { Definitions.storedReportsCount = 0; } }
/// <summary> /// Fetches the report list from the stored file /// </summary> /// <returns>returns the stored report list</returns> public static async Task <List <DriveReport> > GetReportList() { try { var content = await FileHandler.ReadFileContent(Definitions.ReportsFileName, Definitions.ReportsFolderName); var list = JsonConvert.DeserializeObject <List <DriveReport> >(content); if (list == null) { list = new List <DriveReport>(); } return(list); } catch (Exception e) { return(new List <DriveReport>());; } }
/// <summary> /// Removes specific report from the stored list /// </summary> /// <param name="report">the DriveReport to be removed from the list</param> /// <returns>the DriveReport list after removal of the specific DriveReport</returns> public static async Task <List <DriveReport> > RemoveReportFromList(DriveReport report) { try { var content = await FileHandler.ReadFileContent(Definitions.ReportsFileName, Definitions.ReportsFolderName); var list = JsonConvert.DeserializeObject <List <DriveReport> >(content); var item = list.FindIndex(x => x.Date == report.Date && x.route.TotalDistance == report.route.TotalDistance); list.RemoveAt(item); var toBeWritten = JsonConvert.SerializeObject(list); await FileHandler.WriteFileContent(Definitions.ReportsFileName, Definitions.ReportsFolderName, toBeWritten); Definitions.storedReportsCount = list.Count; return(list); } catch (Exception e) { return(new List <DriveReport>());; } }