using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace parkMonitor.LOG
{
///
/// 凭证
///
public class Credence
{
private static List digitCredence = new List();
///
/// 获取一个凭证
///
/// 终端机标识
/// 随机码位数
///
public static string GetOneCredence()
{
string context = "";
//digitCredence = CredentialsGenerator.GetCredential(terminalFlag,num);
if (digitCredence.Count != 0)
{
context = digitCredence[0];
digitCredence.RemoveAt(0);
}
return context;
}
///
/// 读取所有凭证
///
///
public static bool ReadCredence()
{
digitCredence.Clear();
//string date = System.DateTime.Now.ToString("yyyy-MM-dd");
//string filePath = logAddress + "\\\\" + date + "\\\\" + "CREDENCES.log";
string filePath = LogManager.logAddress + "\\\\" + "CREDENCES.log";
try
{
List logLines = null;
if (File.Exists(filePath))
{
logLines = new List(File.ReadAllLines(filePath));
File.Delete(filePath);
}
if (logLines != null)
{
for (int i = 0; i < 300; i++)
{
string logLine = logLines[i];
digitCredence.Add(logLine);
logLines.RemoveAt(i);
}
File.WriteAllLines(filePath, logLines.ToArray());
}
}
catch (Exception e) { Console.WriteLine(e.Message); Log.WriteLog(LogType.process, LogFile.ERROR, "凭证获取失败");return false; }
return true;
}
}
}