BLL
ningshuxia
2023-02-07 813696f6824a86aef0b80b42f00108f1d9a80dcc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
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<T> where T : class, new()
    {
 
        #region Query
 
        /// <summary>
        /// 获取全部
        /// </summary>
        public static List<T> GetAll(string path)
        {
            if (string.IsNullOrEmpty(path))
                return default;
            var fileName = FileHelper.GetFilePath<T>(path);
            var list = FileHelper.GetFileObject<List<T>>(fileName);
            return list;
        }
 
        #endregion
        
        #region Append
        /// <summary>
        /// 附加一条
        /// </summary>
        public static bool Append(string path, T t)
        {
            if (string.IsNullOrEmpty(path))
                return false;
            if (t == null)
                return false;
            var fileName = FileHelper.GetFilePath<T>(path);
            var list = FileHelper.GetFileObject<List<T>>(fileName);
            if (list == null)
                list = new List<T>();
            list.Add(t);
            FileHelper.SaveObjectFile(fileName, list);
            return true;
        }
 
        /// <summary>
        /// 附加多条
        /// </summary>
        public static bool Appends(string path, IEnumerable<T> list)
        {
            if (string.IsNullOrEmpty(path))
                return false;
            if (list == null || list.Count() < 1)
                return false;
            var fileName = FileHelper.GetFilePath<T>(path);
            var srcList = FileHelper.GetFileObject<List<T>>(fileName);
            if (srcList == null)
                srcList = new List<T>();
            srcList.AddRange(list);
            FileHelper.SaveObjectFile(fileName, srcList);
            return true;
        }
        #endregion
 
        #region Cover
        /// <summary>
        /// 用一条覆盖
        /// </summary>
        public static bool Cover(string path, T t)
        {
            if (string.IsNullOrEmpty(path))
                return false;
            if (t == null)
                return false;
            var fileName = FileHelper.GetFilePath<T>(path);
            var list = new List<T>();
            list.Add(t);
            FileHelper.SaveObjectFile(fileName, list);
            return true;
        }
 
        /// <summary>
        /// 用多条覆盖
        /// </summary>
        public static bool Covers(string path, IEnumerable<T> list)
        {
            if (string.IsNullOrEmpty(path))
                return false;
            if (list == null || list.Count() < 1)
                return false;
            var fileName = FileHelper.GetFilePath<T>(path);
            FileHelper.SaveObjectFile(fileName, list);
            return true;
        }
        #endregion
         
        #region Exist
        /// <summary>
        /// 是否存在
        /// </summary>
        public static bool IsExist(string path)
        {
            if (string.IsNullOrEmpty(path))
                return default;
            var fileName = FileHelper.GetFilePath<T>(path);
            return File.Exists(fileName);
 
        } 
        #endregion
 
 
    }
}