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
|
|
}
|
}
|