using IStation.Model;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace IStation.DAL
{
///
/// 监测月数据集
///
public partial class MonthSignalRecordPacket
{
#region Path
///
/// 查询文件路径
///
private string GetMonthSignalRecordDataFolder()
{
return LocalFileConfig.GetMonthSignalRecordDataFolder();
}
///
/// 查询月信号文件路径
///
public string GetMonthSignalRecordFile(int year, int month, int recordCount)
{
return LocalFileConfig.GetMonthSignalRecordFile(year, month, recordCount);
}
#endregion
#region Get
///
/// 查询监测数据集列表
///
public List Get()
{
var rootFolder = this.GetMonthSignalRecordDataFolder();
var fileInfos = this.GetMonthSignalRecordFileInfos(rootFolder);
if (fileInfos == null || fileInfos.Count() < 1)
return default;
var monthSignalRecordPackets = new List(fileInfos.Count);
foreach (var fileInfo in fileInfos)
{
var packet = Get(fileInfo.Year, fileInfo.Month, fileInfo.RecordCount);
if (packet == null)
continue;
monthSignalRecordPackets.Add(packet);
}
return monthSignalRecordPackets;
}
///
/// 查询监测数据集
///
public Model.MonthSignalRecordPacket Get(int year, int month, int recordCount)
{
var filePath = this.GetMonthSignalRecordFile(year, month, recordCount);
if (!File.Exists(filePath))
return default;
var json = File.ReadAllText(filePath);
var monthSignalRecordPacket = JsonHelper.Json2Object(json);
return monthSignalRecordPacket;
}
#endregion
#region Save
///
/// 保存
///
public bool Save(IEnumerable list)
{
if (list == null || list.Count() < 1)
return default;
for (int i = 0; i < list.Count(); i++)
{
var dataSet = list.ElementAt(i);
if (!Save(dataSet))
{
//未做判断
}
}
return true;
}
///
/// 保存
///
public bool Save(Model.MonthSignalRecordPacket rhs)
{
if (rhs == null)
return default;
if (rhs.StationSignalRecords == null || rhs.StationSignalRecords.Count < 1)
return default;
var filePath = GetMonthSignalRecordFile(rhs.Year, rhs.Month, rhs.StationSignalRecords.Count);
var json = JsonHelper.Object2Json(rhs);
File.WriteAllText(filePath, json);
return true;
}
#endregion
///
/// 保存
///
public void Clear()
{
var floder = GetMonthSignalRecordDataFolder();
if (Directory.Exists(floder))
{
Directory.Delete(floder, true);
}
}
}
}