using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Text;
using CommonLib.LOG;
using InfluxDB.Client.Api.Domain;
using Newtonsoft.Json;
namespace CommonLib.Config
{
public class ConfigValue
{
///
///wav文件存档的路径
///
public string WaveFilePath = "D:\\WAV_Data\\card{0}\\line{1}\\FIFO{2}.wav";
///
/// 每PerSampleTimeSecond保存SaveSampleTimeSecond
///
public int SaveSampleTimeSecond = 15;
///
/// 每PerSampleTimeSecond保存SaveSampleTimeSecond
///
public int PerSampleTimeSecond = 60;
///
/// PAC文件的最大保存时间 是不是
///
public int removeFileBeforeDays = 60;
///
/// 分割文件夹的时间,每个文件时长1分钟
///
public TimeSpan spitTime = new TimeSpan(0, 1, 0);
public string m_FileName = string.Empty;
///
/// wav文件夹的最大保存时间
///
public double maxSaveDay = 10;
public class CardInfo
{
public string HostName = string.Empty;
public Boolean Enable = false;
public int FileCnt = 3;
public double[][] threashold = new double[][]
{
new double[]{ 1, 1, 1, 1, 1, 1 },
new double[]{ 1, 1, 1, 1, 1, 1 },
new double[]{ 1, 1, 1, 1, 1, 1 },
new double[]{ 1, 1, 1, 1, 1, 1 },
};
};
public int CardDataErrorRestMinutes = 5;//读卡数据出错休息时间
public string IOCardIP = "192.168.1.187";
public ushort IOCardPort = 50000;
///数据库配置
public class InflexDBServer
{
public string DBName = "OnSite";
public string URL = "http://127.0.0.1:8086";
public string User = "admin";
public string Password = "admin";
public string tokening = string.Empty;
public string ProxyUri = string.Empty;
public ushort ProxyPort = 0;
public InflexDBServer()
{
}
}
public InflexDBServer InflexDBServers = new InflexDBServer();
public List cardInfos = new List();
public ConfigValue()
{
m_FileName = " ";
}
///
/// 加载配置文件
///
///
///
public static ConfigValue InitConfig(string FileName )
{
var entity = new ConfigValue() ;
try
{
string strJSON = string.Empty;
strJSON = System.IO.File.ReadAllText(FileName);
entity = JsonConvert.DeserializeObject(strJSON);
}
catch (Exception ex)
{
LogStorage.Logs.Add(LogLevel.Error, ex.Message + "\n" + ex.StackTrace);
}
finally
{
entity.m_FileName = FileName;
}
return entity;
}
///
/// 保存配置到JSON语句
///
public void SaveConfig()
{
try
{
string strJSON = JsonConvert.SerializeObject(this);
LogStorage.Logs.Add(LogLevel.Trace, "保存配置" + strJSON);
strJSON = strJSON.Replace(",", ",\r\n");
System.IO.File.WriteAllText(this.m_FileName, strJSON);
}
catch (Exception ex)
{
LogStorage.Logs.Add(LogLevel.Error, ex.Message + "\n" + ex.StackTrace);
}
}
}
}