public static WriteFileContent ( string filename, string foldername, string content ) : Task |
||
filename | string | the name of the file |
foldername | string | the name of the folder containing the file |
content | string | The content to be written to the file |
return | 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> /// Removes all reports from the stored list /// </summary> /// <returns>true on success, false on failure</returns> public static async Task <bool> DeleteEntireList() { try { var list = new List <DriveReport>(); var toBeWritten = JsonConvert.SerializeObject(list); await FileHandler.WriteFileContent(Definitions.ReportsFileName, Definitions.ReportsFolderName, toBeWritten); Definitions.storedReportsCount = list.Count; return(true); } catch (Exception e) { return(false); } }
/// <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>());; } }