duheng
9 天以前 4de480ec624d3b79ca690dc906e10cd2fbdc9be7
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
using System;
using System.IO;
using System.Reflection;
 
namespace IStation.DAL
{
    /// <summary>
    /// 监测数据集配置
    /// </summary>
    public class LocalFileConfig
    {
        /// <summary>
        /// 根目录
        /// </summary>
        public static string RootDirectory
        {
            get
            {
                if (string.IsNullOrEmpty(_root_directory))
                {
                    if (DataFolderHelper.IsExeExcute)
                    {
                        var directory = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory).FullName;
                        _root_directory = directory;
                    }
                    else
                    {
                        var directory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); 
                        _root_directory = directory;
                    }
 
                }
                return _root_directory;
            }
        }
        private static string _root_directory;
 
 
 
        /// <summary>
        /// 工作文件夹
        /// </summary>
        public static string WorkFolder
        {
            get
            {
                return Settings.File.WorkFolder;
            }
        }
 
        /// <summary>
        /// 版本
        /// </summary>
        public static string Versions
        {
            get
            {
                return Settings.File.Versions;
            }
        }
 
        /// <summary>
        /// 监测数据集文件夹
        /// </summary>
        public static string MonitorDataFolder
        {
            get { return _monitor_data_folder; }
        }
        private static string _monitor_data_folder = "MonitorData";
 
 
        /// <summary>
        /// 监测数据集文件夹
        /// </summary>
        public static string MonthSignalRecordFolder
        {
            get { return _month_signal_record_folder; }
        }
        private static string _month_signal_record_folder = "MonthSignalRecord";
 
 
        /// <summary>
        /// 信号记录文件扩展名
        /// </summary>
        public static string SignalRecordFileExtension
        {
            get
            {
                return _signal_record_file_extension;
            }
        }
        private static string _signal_record_file_extension = ".csv";
 
 
        /// <summary>
        /// 月信号记录文件扩展名
        /// </summary>
        public static string MonthSignalRecordFileExtension
        {
            get
            {
                return _month_signal_record_file_extension;
            }
        }
        private static string _month_signal_record_file_extension = ".txt";
 
        /// <summary>
        /// 文件名间隔字符
        /// </summary>
        public static char Separator
        {
            get
            {
                return _separator;
            }
        }
        private const char _separator = '-';
 
        #region Path
 
        /// <summary>
        /// 查询数据文件夹路径
        /// </summary>
        public static string GetDataPath()
        {
            var path = Path.Combine(RootDirectory, "Data");
            if (!Directory.Exists(path))
                Directory.CreateDirectory(path);
            return path;
        }
 
        /// <summary>
        /// 查询工作文件夹路径
        /// </summary>
        public static string GetWorkPath()
        {
            var dataPath = GetDataPath();
            var workPath = Path.Combine(dataPath, WorkFolder);
            if (!Directory.Exists(workPath))
                Directory.CreateDirectory(workPath);
            return workPath;
        }
 
        /// <summary>
        /// 查询版本文件夹路径
        /// </summary>
        public static string GetVersionsPath()
        {
            var workPath = GetWorkPath();
            var projectPath = Path.Combine(workPath, Versions);
            if (!Directory.Exists(projectPath))
                Directory.CreateDirectory(projectPath);
            return projectPath;
        }
 
        #region MonitorData 
 
        /// <summary>
        /// 查询监测数据集文件夹
        /// </summary> 
        public static string GetMonitorDataFolder()
        {
            var versionsFolder = GetVersionsPath();
            if (!Directory.Exists(versionsFolder))
                Directory.CreateDirectory(versionsFolder);
            var monitorDataSetFolder = Path.Combine(versionsFolder, MonitorDataFolder);
            if (!Directory.Exists(monitorDataSetFolder))
                Directory.CreateDirectory(monitorDataSetFolder);
            return monitorDataSetFolder;
        }
 
        /// <summary>
        /// 查询日期文件夹
        /// </summary>
        public static string GetMonitorDataMonthFolder(int year, int month)
        {
            var monitorDataSetFolder = GetMonitorDataFolder();
            var timeFolderName = "";
            if (month < 10)
            {
                timeFolderName = $"{year}{Separator}0{month}";
            }
            else
            {
                timeFolderName = $"{year}{Separator}{month}";
            }
            var timeFolderPath = Path.Combine(monitorDataSetFolder, timeFolderName);
            if (!Directory.Exists(timeFolderPath))
                Directory.CreateDirectory(timeFolderPath);
            return timeFolderPath;
        }
 
        /// <summary>
        /// 查询监测数据集文件夹 
        /// </summary>
        public static string GetMonitorDataSetFolder(long monitorPointId, int year, int month)
        {
            var timeFolder = GetMonitorDataMonthFolder(year, month);
            var monitorPointFolderPath = Path.Combine(timeFolder, monitorPointId.ToString());
            if (!Directory.Exists(monitorPointFolderPath))
                Directory.CreateDirectory(monitorPointFolderPath);
            return monitorPointFolderPath;
        }
 
        /// <summary>
        /// 查询信号记录文件路径
        /// </summary>
        public static string GetSignalRecordFile(long monitorPointId, long signaId, int year, int month)
        {
            var monitorPointFolder = GetMonitorDataSetFolder(monitorPointId, year, month);
            var fileName = Path.Combine(monitorPointFolder, signaId + SignalRecordFileExtension);
            return fileName;
        }
        #endregion
 
        #region MonthSignalRecordPacket
 
        /// <summary>
        /// 查询月信号记录文件夹
        /// </summary> 
        public static string GetMonthSignalRecordDataFolder()
        {
            var versionsFolder = GetVersionsPath();
            if (!Directory.Exists(versionsFolder))
                Directory.CreateDirectory(versionsFolder);
            var monitorDataSetFolder = Path.Combine(versionsFolder, MonthSignalRecordFolder);
            if (!Directory.Exists(monitorDataSetFolder))
                Directory.CreateDirectory(monitorDataSetFolder);
            return monitorDataSetFolder;
        }
 
        /// <summary>
        /// 查询月信号记录文件路径
        /// </summary>
        public static string GetMonthSignalRecordFile(int year, int month, int recordCount)
        {
            var monitorPointFolder = GetMonthSignalRecordDataFolder();
            var timeFolderName = "";
            if (month < 10)
            {
                timeFolderName = $"{year}{Separator}0{month}{Separator}{recordCount}";
            }
            else
            {
                timeFolderName = $"{year}{Separator}{month}{Separator}{recordCount}";
            }
            var fileName = Path.Combine(monitorPointFolder, timeFolderName + MonthSignalRecordFileExtension);
            return fileName;
        }
 
        #endregion
 
 
        #endregion
 
    }
}