using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace IStation.DAL.LocalFile { public class FileSrcHelper where T : class, new() { #region Query /// /// 获取全部 /// public static List GetAll(string path) { if (string.IsNullOrEmpty(path)) return default; var fileName = FileHelper.GetFilePath(path); var list = FileHelper.GetFileObject>(fileName); return list; } #endregion #region Append /// /// 附加一条 /// public static bool Append(string path, T t) { if (string.IsNullOrEmpty(path)) return false; if (t == null) return false; var fileName = FileHelper.GetFilePath(path); var list = FileHelper.GetFileObject>(fileName); if (list == null) list = new List(); list.Add(t); FileHelper.SaveObjectFile(fileName, list); return true; } /// /// 附加多条 /// public static bool Appends(string path, IEnumerable list) { if (string.IsNullOrEmpty(path)) return false; if (list == null || list.Count() < 1) return false; var fileName = FileHelper.GetFilePath(path); var srcList = FileHelper.GetFileObject>(fileName); if (srcList == null) srcList = new List(); srcList.AddRange(list); FileHelper.SaveObjectFile(fileName, srcList); return true; } #endregion #region Cover /// /// 用一条覆盖 /// public static bool Cover(string path, T t) { if (string.IsNullOrEmpty(path)) return false; if (t == null) return false; var fileName = FileHelper.GetFilePath(path); var list = new List(); list.Add(t); FileHelper.SaveObjectFile(fileName, list); return true; } /// /// 用多条覆盖 /// public static bool Covers(string path, IEnumerable list) { if (string.IsNullOrEmpty(path)) return false; if (list == null || list.Count() < 1) return false; var fileName = FileHelper.GetFilePath(path); FileHelper.SaveObjectFile(fileName, list); return true; } #endregion #region Exist /// /// 是否存在 /// public static bool IsExist(string path) { if (string.IsNullOrEmpty(path)) return default; var fileName = FileHelper.GetFilePath(path); return File.Exists(fileName); } #endregion } }