using System;
|
using System.Collections.Generic;
|
using System.IO;
|
using System.Text;
|
using WIDESEA_Core.Utilities;
|
|
namespace WIDESEA_Services.Services.VueMonitorServices
|
{
|
public class VueMonitorService
|
{
|
/// <summary>
|
/// 获取所有站台的信息
|
/// </summary>
|
/// <returns></returns>
|
public static WebResponseContent AllStationData()
|
{
|
WebResponseContent content = new WebResponseContent();
|
try
|
{
|
List<FileNames> tmpList = new List<FileNames>();
|
GetallDirectory(tmpList, "D:/WCS_log");
|
|
|
|
content.OK(data: tmpList);
|
}
|
catch(Exception ex)
|
{
|
content.Error(ex.Message);
|
}
|
return content;
|
}
|
|
|
//获得指定路径下所有文件名
|
public static List<FileNames> getFileName(List<FileNames> list, string filepath)
|
{
|
DirectoryInfo root = new DirectoryInfo(filepath);
|
foreach (FileInfo f in root.GetFiles())
|
{
|
DateTime currtlyTime = DateTime.Now;
|
TimeSpan ts = currtlyTime.Subtract(f.CreationTime);
|
|
if (f.Name.Contains("20") && Math.Abs(ts.Days) < 100)
|
{
|
list.Add(new FileNames
|
{
|
label = f.Name,
|
});
|
}
|
}
|
return list;
|
}
|
//获得指定路径下的所有子目录名
|
// <param name="list">文件列表</param>
|
// <param name="path">文件夹路径</param>
|
public static List<FileNames> GetallDirectory(List<FileNames> list, string path)
|
{
|
DirectoryInfo root = new DirectoryInfo(path);
|
var dirs = root.GetDirectories();
|
if (dirs.Length > 0)
|
{
|
foreach (DirectoryInfo d in dirs)
|
{
|
DateTime currtlyTime = DateTime.Now;
|
TimeSpan ts = currtlyTime.Subtract(d.CreationTime);
|
if (d.Name.Contains("20"))
|
{
|
if (Math.Abs(ts.Days) < 100)
|
{
|
list.Add(new FileNames
|
{
|
label = d.Name,
|
children = GetallDirectory(new List<FileNames>(), d.FullName)
|
});
|
}
|
}
|
else
|
{
|
list.Add(new FileNames
|
{
|
label = d.Name,
|
children = GetallDirectory(new List<FileNames>(), d.FullName)
|
});
|
}
|
}
|
}
|
list = getFileName(list, path);
|
return list;
|
}
|
|
|
}
|
|
|
public class FileNames
|
{
|
public string label { get; set; }
|
public List<FileNames> children { get; set; }
|
}
|
|
|
}
|