ningshuxia
2025-04-03 4917fb959e2befec07a693e72d7010c09494ec7c
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
using System.IO;
 
namespace IStation.DAL
{
    /// <summary>
    /// 文件辅助类
    /// </summary>
    public class FileHelper
    {
 
        /// <summary>
        /// 查询数据文件夹路径
        /// </summary>
        public static string GetDataFolder()
        {
            var path = Path.Combine(SettingsD.File.RootDirectory, SettingsD.File.DataFolder);
            if (!Directory.Exists(path))
                Directory.CreateDirectory(path);
            return path;
        }
 
        /// <summary>
        /// 查询工作文件夹路径
        /// </summary>
        public static string GetWorkFolder()
        {
            var dataFolder = GetDataFolder();
            var workFolder = Path.Combine(dataFolder, SettingsD.File.WorkFolder);
            if (!Directory.Exists(workFolder))
                Directory.CreateDirectory(workFolder);
            return workFolder;
        }
 
        /// <summary>
        /// 查询项目文件夹路径
        /// </summary>
        public static string GetProjectFolder(long projectId)
        {
            var workFolder = GetWorkFolder();
            var projectFolder = Path.Combine(workFolder, projectId.ToString());
            if (!Directory.Exists(projectFolder))
                Directory.CreateDirectory(projectFolder);
            return projectFolder;
        }
 
        /// <summary>
        /// 查询文件路径
        /// </summary>
        public static string GetFilePath<T>(long projectId)
        {
            var projectPath = GetProjectFolder(projectId);
            var objType = typeof(T);
            var fileName = Path.Combine(projectPath, objType.Name + SettingsD.File.FileExtension);
            return fileName;
        }
 
        /// <summary>
        /// 查询文件路径
        /// </summary>
        public static string GetFilePath<T>(string folderPath) where T : class
        {
            if (!Directory.Exists(folderPath))
                Directory.CreateDirectory(folderPath);
            var objType = typeof(T);
            var fileName = Path.Combine(folderPath, objType.Name + SettingsD.File.FileExtension);
            return fileName;
        }
 
    }
}