using System; using System.IO; using System.Reflection; namespace IStation.DAL { /// /// 监测数据集配置 /// public class LocalFileConfig { /// /// 根目录 /// 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; /// /// 工作文件夹 /// public static string WorkFolder { get { return Settings.File.WorkFolder; } } /// /// 版本 /// public static string Versions { get { return Settings.File.Versions; } } /// /// 监测数据集文件夹 /// public static string MonitorDataFolder { get { return _monitor_data_folder; } } private static string _monitor_data_folder = "MonitorData"; /// /// 监测数据集文件夹 /// public static string MonthSignalRecordFolder { get { return _month_signal_record_folder; } } private static string _month_signal_record_folder = "MonthSignalRecord"; /// /// 信号记录文件扩展名 /// public static string SignalRecordFileExtension { get { return _signal_record_file_extension; } } private static string _signal_record_file_extension = ".csv"; /// /// 月信号记录文件扩展名 /// public static string MonthSignalRecordFileExtension { get { return _month_signal_record_file_extension; } } private static string _month_signal_record_file_extension = ".txt"; /// /// 文件名间隔字符 /// public static char Separator { get { return _separator; } } private const char _separator = '-'; #region Path /// /// 查询数据文件夹路径 /// public static string GetDataPath() { var path = Path.Combine(RootDirectory, "Data"); if (!Directory.Exists(path)) Directory.CreateDirectory(path); return path; } /// /// 查询工作文件夹路径 /// public static string GetWorkPath() { var dataPath = GetDataPath(); var workPath = Path.Combine(dataPath, WorkFolder); if (!Directory.Exists(workPath)) Directory.CreateDirectory(workPath); return workPath; } /// /// 查询版本文件夹路径 /// public static string GetVersionsPath() { var workPath = GetWorkPath(); var projectPath = Path.Combine(workPath, Versions); if (!Directory.Exists(projectPath)) Directory.CreateDirectory(projectPath); return projectPath; } #region MonitorData /// /// 查询监测数据集文件夹 /// 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; } /// /// 查询日期文件夹 /// 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; } /// /// 查询监测数据集文件夹 /// 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; } /// /// 查询信号记录文件路径 /// 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 /// /// 查询月信号记录文件夹 /// 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; } /// /// 查询月信号记录文件路径 /// 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 } }