/// <summary> /// Check If store files already exists for season passed /// </summary> /// <param name="season">Season to check for</param> /// <returns>if file already exists</returns> public bool CheckStoreAlreadyExists(string season) { if (string.IsNullOrEmpty(season)) { return(false); } return(File.Exists(FileNameHelper.GetFileName(season))); }
/// <summary> /// Read json from store & output as list of match's /// </summary> /// <param name="season">Season store to check</param> /// <returns>List of match objects</returns> public List <Match> ReadFromStore(String season) { if (fileStore.CheckStoreAlreadyExists(season)) { var jsonString = File.ReadAllText(FileNameHelper.GetFileName(season)); return(JsonSerializer.Deserialize <List <Match> >(jsonString)); } else { return(null); } }
/// <summary> /// Create new File store for season /// </summary> /// <param name="season">season to create store for</param> /// <returns>if store is created successfully</returns> public string CreateNewStoreForSeason(string season) { try { File.CreateText(FileNameHelper.GetFileName(season)).Close(); return(FileNameHelper.GetFileName(season)); } catch (Exception ex) { Trace.WriteLine(ex.Message); return(null); } }
/// <summary> /// Remove store for season passed /// </summary> /// <param name="season">season to remove</param> /// <returns>if remove was succcessful</returns> public bool RemoveExistingStore(string season) { string fileName = FileNameHelper.GetFileName(season); if (File.Exists(fileName)) { try { File.Delete(fileName); } catch (Exception ex) { Trace.WriteLine(ex.Message); return(false); } return(true); } return(true); }
/// <summary> /// Write to store as json list of match's /// </summary> /// <param name="matches">Match's to add to store</param> /// <param name="season">store season id</param> /// <returns>if add was successful</returns> public bool WriteToStore(List <Match> matches, string season) { if (matches == null || !matches.Any()) { return(false); } try { var jsonString = JsonSerializer.Serialize(matches); File.WriteAllText(FileNameHelper.GetFileName(season), jsonString); } catch (Exception ex) { Trace.WriteLine(ex.Message); return(false); } return(true); }
/// <summary> /// Read json from store & output as list of match's for multiple years /// </summary> /// <param name="startYear">start of season</param> /// <param name="endYear">end of season</param> /// <returns>list of match objects</returns> public List <Match> ReadFromStore(int startYear, int endYear) { return(this.ReadFromStore(FileNameHelper.GetSeasonIdentifier(startYear, endYear))); }
/// <summary> /// Write to store as Json list of match's for multiple years /// </summary> /// <param name="matches">Match's to add to store</param> /// <param name="startYear">store start year</param> /// <param name="endYear">Store end year</param> /// <returns>If add was successful</returns> public bool WriteToStore(List <Match> matches, int startYear, int endYear) { return(this.WriteToStore(matches, FileNameHelper.GetSeasonIdentifier(startYear, endYear))); }
/// <summary> /// Create new file store beteen given years /// </summary> /// <param name="startYear">Start of season</param> /// <param name="endYear">end of season</param> /// <returns>If Create store was successful</returns> public string CreateNewStoreForSeason(int startYear, int endYear) { return(this.CreateNewStoreForSeason(FileNameHelper.GetSeasonIdentifier(startYear, endYear))); }
/// <summary> /// Remove Store for season between years passed /// </summary> /// <param name="startYear">start of season</param> /// <param name="endYear">end of season</param> /// <returns>if Remove was successful</returns> public bool RemoveExistingStore(int startYear, int endYear) { return(this.RemoveExistingStore(FileNameHelper.GetSeasonIdentifier(startYear, endYear))); }
/// <summary> /// Check if store file already Exists for season /// </summary> /// <param name="startYear">Start year of season</param> /// <param name="endYear">End year of season</param> /// <returns>If files already exists</returns> public bool CheckStoreAlreadyExists(int startYear, int endYear) { return(CheckStoreAlreadyExists(FileNameHelper.GetSeasonIdentifier(startYear, endYear))); }