2021-12-14 18:39:55 +08:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using System.Xml;
|
|
|
|
|
|
using System.IO;
|
2021-12-20 18:34:41 +08:00
|
|
|
|
using System.Windows.Forms;
|
2021-12-14 18:39:55 +08:00
|
|
|
|
|
|
|
|
|
|
namespace mainProgram
|
|
|
|
|
|
{
|
2022-03-15 10:19:53 +08:00
|
|
|
|
public delegate void RadCompleteDelegate();//申明委托类型:福亮度完成后调用的委托
|
2022-01-14 11:56:12 +08:00
|
|
|
|
|
|
|
|
|
|
public class DateFolder : IComparable//接口
|
|
|
|
|
|
{
|
|
|
|
|
|
private int mYear;
|
|
|
|
|
|
private int mMonth;
|
|
|
|
|
|
private int mDay;
|
|
|
|
|
|
|
|
|
|
|
|
//int hout;
|
|
|
|
|
|
//int minute;
|
|
|
|
|
|
//int second;
|
|
|
|
|
|
|
|
|
|
|
|
public string mDateFolder;
|
|
|
|
|
|
|
|
|
|
|
|
public DateFolder(string dateFolder)
|
|
|
|
|
|
{
|
|
|
|
|
|
string[] tmp = dateFolder.Split('_');
|
|
|
|
|
|
|
|
|
|
|
|
mYear = int.Parse(tmp[0]);
|
|
|
|
|
|
mMonth = int.Parse(tmp[1]);
|
|
|
|
|
|
mDay = int.Parse(tmp[2]);
|
|
|
|
|
|
|
|
|
|
|
|
mDateFolder = dateFolder;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public string GetDateFolder()
|
|
|
|
|
|
{
|
|
|
|
|
|
return mDateFolder;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//重载运算符
|
|
|
|
|
|
public static bool operator >(DateFolder a, DateFolder b)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (a.mYear > b.mYear)
|
|
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (a.mYear < b.mYear)
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (a.mYear == b.mYear)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (a.mMonth > b.mMonth)
|
|
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (a.mMonth < b.mMonth)
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (a.mMonth == b.mMonth)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (a.mDay > b.mDay)
|
|
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (a.mDay < b.mDay)
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (a.mDay == b.mDay)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
public static bool operator <(DateFolder a, DateFolder b)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (a.mYear < b.mYear)
|
|
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (a.mYear > b.mYear)
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (a.mYear == b.mYear)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (a.mMonth < b.mMonth)
|
|
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (a.mMonth > b.mMonth)
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (a.mMonth == b.mMonth)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (a.mDay < b.mDay)
|
|
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (a.mDay > b.mDay)
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (a.mDay == b.mDay)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//负数值:当前对象小于参数对象;
|
|
|
|
|
|
//正数值:当前对象大于参数对象;
|
|
|
|
|
|
//零:两个对象在比较时相等;
|
|
|
|
|
|
public int CompareTo(object obj)//IComparable接口
|
|
|
|
|
|
{
|
|
|
|
|
|
DateFolder df = (DateFolder)obj;
|
|
|
|
|
|
|
|
|
|
|
|
if (this.mYear < df.mYear)
|
|
|
|
|
|
{
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (this.mYear > df.mYear)
|
|
|
|
|
|
{
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (this.mYear == df.mYear)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (this.mMonth < df.mMonth)
|
|
|
|
|
|
{
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (this.mMonth > df.mMonth)
|
|
|
|
|
|
{
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (this.mMonth == df.mMonth)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (this.mDay < df.mDay)
|
|
|
|
|
|
{
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (this.mDay > df.mDay)
|
|
|
|
|
|
{
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (this.mDay == df.mDay)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-12-14 18:39:55 +08:00
|
|
|
|
public class ProjectManager
|
|
|
|
|
|
{
|
2022-09-07 18:44:41 +08:00
|
|
|
|
public ProjectManager(string projectFile)
|
2021-12-14 18:39:55 +08:00
|
|
|
|
{
|
2022-09-07 18:44:41 +08:00
|
|
|
|
string sourceFileName = Path.GetFileName(projectFile);//获取文件名
|
|
|
|
|
|
mProjectFile = projectFile;
|
|
|
|
|
|
mProjectPath = Path.GetDirectoryName(projectFile);
|
|
|
|
|
|
mProjectName = Path.GetFileNameWithoutExtension(projectFile);
|
2021-12-14 18:39:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-06-16 13:26:55 +08:00
|
|
|
|
private string mProjectFile;
|
2022-09-07 18:44:41 +08:00
|
|
|
|
private string mProjectName;
|
2022-06-16 13:26:55 +08:00
|
|
|
|
|
2021-12-14 18:39:55 +08:00
|
|
|
|
private string mProjectPath;
|
2021-12-16 18:40:51 +08:00
|
|
|
|
private string mMetadataPath;
|
2021-12-14 18:39:55 +08:00
|
|
|
|
private string mRawPath;
|
|
|
|
|
|
private string mRadPath;
|
2022-01-14 11:56:12 +08:00
|
|
|
|
public string mSifPath;
|
|
|
|
|
|
public string mSifTmpPath;
|
|
|
|
|
|
|
|
|
|
|
|
private int mCsvFileCount;
|
2021-12-16 18:40:51 +08:00
|
|
|
|
|
2021-12-14 18:39:55 +08:00
|
|
|
|
public string ProjectPath
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return mProjectPath;
|
|
|
|
|
|
}
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
|
|
|
|
|
mProjectPath = value;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-09-07 18:44:41 +08:00
|
|
|
|
public string ProjectName
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return mProjectName;
|
|
|
|
|
|
}
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
|
|
|
|
|
mProjectName = value;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-03-15 10:19:53 +08:00
|
|
|
|
public string MetadataPath
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return mMetadataPath;
|
|
|
|
|
|
}
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
|
|
|
|
|
mMetadataPath = value;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
public string RawPath
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return mRawPath;
|
|
|
|
|
|
}
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
|
|
|
|
|
mRawPath = value;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
public string RadPath
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return mRadPath;
|
|
|
|
|
|
}
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
|
|
|
|
|
mRadPath = value;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
public string SifPath
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
return mSifPath;
|
|
|
|
|
|
}
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
|
|
|
|
|
mSifPath = value;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-06-16 13:26:55 +08:00
|
|
|
|
//返回值:0:代表成功;1:代表定标文件夹有错误;2:代表数据文件夹有错误;3:代表工程路径有错误;
|
|
|
|
|
|
public int CreateProject(string calFilePath, string dataPath)
|
2021-12-14 18:39:55 +08:00
|
|
|
|
{
|
2021-12-16 18:40:51 +08:00
|
|
|
|
if (mProjectPath.Length == 0)
|
|
|
|
|
|
{
|
2022-06-16 13:26:55 +08:00
|
|
|
|
return 3;
|
2021-12-16 18:40:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-06-16 15:45:54 +08:00
|
|
|
|
//DelectDir(mProjectPath);//删除工程路径下的所有内容 → 应该删除此行代码,删除数据太危险
|
2022-06-16 13:26:55 +08:00
|
|
|
|
|
2021-12-16 18:40:51 +08:00
|
|
|
|
CreateProjectStructure();
|
2022-01-14 11:56:12 +08:00
|
|
|
|
|
2022-06-16 13:26:55 +08:00
|
|
|
|
bool re1 = CopyCalFiles2Project(calFilePath);//复制定标文件到工程结构对应文件夹
|
|
|
|
|
|
if (!re1)
|
|
|
|
|
|
{
|
|
|
|
|
|
DelectDir(mProjectPath);
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
mCsvFileCount = 0;//类的变量
|
|
|
|
|
|
bool re2 = CopyFiles2Project(dataPath, ref mCsvFileCount);//复制原始数据文件到工程结构对应文件夹
|
|
|
|
|
|
if (!re2)
|
|
|
|
|
|
{
|
|
|
|
|
|
DelectDir(mProjectPath);
|
|
|
|
|
|
return 2;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//将文件个数写入到可执行文件所在目录 → 打开工程时需要读取
|
|
|
|
|
|
BinaryWriter bw = new BinaryWriter(new FileStream(mProjectFile, FileMode.Create));//Path.Combine(mMetadataPath, "CsvFileCount.dat")
|
|
|
|
|
|
bw.Write(mCsvFileCount);
|
|
|
|
|
|
bw.Close();
|
2022-01-14 11:56:12 +08:00
|
|
|
|
|
|
|
|
|
|
|
2021-12-16 18:40:51 +08:00
|
|
|
|
|
|
|
|
|
|
////创建工程元数据
|
|
|
|
|
|
//string myXMLFilePath = mMetadataPath + "/metadata.xml";
|
|
|
|
|
|
////生成xml文件
|
|
|
|
|
|
//GenerateXMLFile(myXMLFilePath);
|
|
|
|
|
|
////遍历xml文件的信息
|
|
|
|
|
|
//GetXMLInformation(myXMLFilePath);
|
|
|
|
|
|
////修改xml文件的信息
|
|
|
|
|
|
//ModifyXmlInformation(myXMLFilePath);
|
|
|
|
|
|
////向xml文件添加节点信息
|
|
|
|
|
|
//AddXmlInformation(myXMLFilePath);
|
|
|
|
|
|
////删除指定节点信息
|
|
|
|
|
|
//DeleteXmlInformation(myXMLFilePath);
|
|
|
|
|
|
|
2022-06-16 13:26:55 +08:00
|
|
|
|
return 0;
|
2021-12-14 18:39:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-03-15 10:19:53 +08:00
|
|
|
|
public bool OpenProject()
|
2021-12-14 18:39:55 +08:00
|
|
|
|
{
|
2022-03-15 10:19:53 +08:00
|
|
|
|
if (!Directory.Exists(mProjectPath))
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-12-20 18:34:41 +08:00
|
|
|
|
mMetadataPath = Path.Combine(mProjectPath, ".project");
|
|
|
|
|
|
mRawPath = Path.Combine(mProjectPath, "1raw");
|
|
|
|
|
|
mRadPath = Path.Combine(mProjectPath, "2rad");
|
|
|
|
|
|
mSifPath = Path.Combine(mProjectPath, "3sif");
|
|
|
|
|
|
|
2022-03-15 10:19:53 +08:00
|
|
|
|
if (Directory.Exists(mMetadataPath) & Directory.Exists(mRawPath) & Directory.Exists(mRadPath) & Directory.Exists(mSifPath))
|
|
|
|
|
|
{
|
2022-06-16 13:26:55 +08:00
|
|
|
|
BinaryReader br = new BinaryReader(new FileStream(mProjectFile, FileMode.Open));
|
2022-03-15 10:19:53 +08:00
|
|
|
|
mCsvFileCount = br.ReadInt32();
|
|
|
|
|
|
br.Close();
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-01-14 11:56:12 +08:00
|
|
|
|
|
2021-12-20 18:34:41 +08:00
|
|
|
|
//if (false == Directory.Exists(mMetadataPath))
|
|
|
|
|
|
//{
|
|
|
|
|
|
// Directory.CreateDirectory(mMetadataPath);
|
|
|
|
|
|
|
|
|
|
|
|
// MessageBox.Show("工程打开成功!", "提示");
|
|
|
|
|
|
//}
|
|
|
|
|
|
//if (false == Directory.Exists(mRawPath))
|
|
|
|
|
|
//{
|
|
|
|
|
|
// Directory.CreateDirectory(mRawPath);
|
|
|
|
|
|
//}
|
|
|
|
|
|
//if (false == Directory.Exists(mRadPath))
|
|
|
|
|
|
//{
|
|
|
|
|
|
// Directory.CreateDirectory(mRadPath);
|
|
|
|
|
|
//}
|
|
|
|
|
|
//if (false == Directory.Exists(mSifPath))
|
|
|
|
|
|
//{
|
|
|
|
|
|
// Directory.CreateDirectory(mSifPath);
|
|
|
|
|
|
//}
|
2021-12-14 18:39:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void SaveProject()
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void AddData()
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-03-15 10:19:53 +08:00
|
|
|
|
public void DeleteFile(string name)
|
2021-12-14 18:39:55 +08:00
|
|
|
|
{
|
2022-03-15 10:19:53 +08:00
|
|
|
|
File.Delete(name);
|
2021-12-14 18:39:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//生成工程元数据
|
|
|
|
|
|
public void GenerateXMLFile(string xmlFilePath)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
//初始化一个xml实例
|
|
|
|
|
|
XmlDocument myXmlDoc = new XmlDocument();
|
|
|
|
|
|
//创建xml的根节点
|
|
|
|
|
|
XmlElement rootElement = myXmlDoc.CreateElement("Computers");
|
|
|
|
|
|
//将根节点加入到xml文件中(AppendChild)
|
|
|
|
|
|
myXmlDoc.AppendChild(rootElement);
|
|
|
|
|
|
|
|
|
|
|
|
//初始化第一层的第一个子节点
|
|
|
|
|
|
XmlElement firstLevelElement1 = myXmlDoc.CreateElement("Computer");
|
|
|
|
|
|
//填充第一层的第一个子节点的属性值(SetAttribute)
|
|
|
|
|
|
firstLevelElement1.SetAttribute("ID", "11111111");
|
|
|
|
|
|
firstLevelElement1.SetAttribute("Description", "Made in China");
|
|
|
|
|
|
//将第一层的第一个子节点加入到根节点下
|
|
|
|
|
|
rootElement.AppendChild(firstLevelElement1);
|
|
|
|
|
|
//初始化第二层的第一个子节点
|
|
|
|
|
|
XmlElement secondLevelElement11 = myXmlDoc.CreateElement("name");
|
|
|
|
|
|
//填充第二层的第一个子节点的值(InnerText)
|
|
|
|
|
|
secondLevelElement11.InnerText = "Lenovo";
|
|
|
|
|
|
firstLevelElement1.AppendChild(secondLevelElement11);
|
|
|
|
|
|
XmlElement secondLevelElement12 = myXmlDoc.CreateElement("price");
|
|
|
|
|
|
secondLevelElement12.InnerText = "5000";
|
|
|
|
|
|
firstLevelElement1.AppendChild(secondLevelElement12);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
XmlElement firstLevelElement2 = myXmlDoc.CreateElement("Computer");
|
|
|
|
|
|
firstLevelElement2.SetAttribute("ID", "2222222");
|
|
|
|
|
|
firstLevelElement2.SetAttribute("Description", "Made in USA");
|
|
|
|
|
|
rootElement.AppendChild(firstLevelElement2);
|
|
|
|
|
|
XmlElement secondLevelElement21 = myXmlDoc.CreateElement("name");
|
|
|
|
|
|
secondLevelElement21.InnerText = "IBM";
|
|
|
|
|
|
firstLevelElement2.AppendChild(secondLevelElement21);
|
|
|
|
|
|
XmlElement secondLevelElement22 = myXmlDoc.CreateElement("price");
|
|
|
|
|
|
secondLevelElement22.InnerText = "10000";
|
|
|
|
|
|
firstLevelElement2.AppendChild(secondLevelElement22);
|
|
|
|
|
|
|
|
|
|
|
|
//将xml文件保存到指定的路径下
|
|
|
|
|
|
myXmlDoc.Save(xmlFilePath);
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
Console.WriteLine(ex.ToString());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void GetXMLInformation(string xmlFilePath)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
XmlDocument myXmlDoc = new XmlDocument();//初始化一个xml实例
|
|
|
|
|
|
myXmlDoc.Load(xmlFilePath);//加载xml文件(参数为xml文件的路径)
|
|
|
|
|
|
|
|
|
|
|
|
XmlNode rootNode = myXmlDoc.SelectSingleNode("Computers");//获得第一个姓名匹配的节点(SelectSingleNode):此xml文件的根节点
|
|
|
|
|
|
|
|
|
|
|
|
string innerXmlInfo = rootNode.InnerXml.ToString();//分别获得该节点的InnerXml和OuterXml信息
|
|
|
|
|
|
string outerXmlInfo = rootNode.OuterXml.ToString();
|
|
|
|
|
|
|
|
|
|
|
|
XmlNodeList firstLevelNodeList = rootNode.ChildNodes;//获得该节点的子节点(即:该节点的第一层子节点)
|
|
|
|
|
|
foreach (XmlNode node in firstLevelNodeList)
|
|
|
|
|
|
{
|
|
|
|
|
|
XmlAttributeCollection attributeCol = node.Attributes;//获得该节点的属性集合
|
|
|
|
|
|
foreach (XmlAttribute attri in attributeCol)
|
|
|
|
|
|
{
|
|
|
|
|
|
//获取属性名称与属性值
|
|
|
|
|
|
string name = attri.Name;
|
|
|
|
|
|
string value = attri.Value;
|
|
|
|
|
|
Console.WriteLine("{0} = {1}", name, value);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//判断此节点是否还有子节点
|
|
|
|
|
|
if (node.HasChildNodes)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
XmlNode secondLevelNode1 = node.FirstChild;//获取该节点的第一个子节点
|
|
|
|
|
|
string name = secondLevelNode1.Name;//获取该节点的名字
|
|
|
|
|
|
string innerText = secondLevelNode1.InnerText;//获取该节点的值(即:InnerText)
|
|
|
|
|
|
Console.WriteLine("{0} = {1}", name, innerText);
|
|
|
|
|
|
|
|
|
|
|
|
XmlNode secondLevelNode2 = node.ChildNodes[1];//获取该节点的第二个子节点(用数组下标获取)
|
|
|
|
|
|
name = secondLevelNode2.Name;
|
|
|
|
|
|
innerText = secondLevelNode2.InnerText;
|
|
|
|
|
|
Console.WriteLine("{0} = {1}", name, innerText);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
Console.WriteLine(ex.ToString());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void ModifyXmlInformation(string xmlFilePath)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
XmlDocument myXmlDoc = new XmlDocument();
|
|
|
|
|
|
myXmlDoc.Load(xmlFilePath);
|
|
|
|
|
|
|
|
|
|
|
|
XmlNode rootNode = myXmlDoc.FirstChild;
|
|
|
|
|
|
XmlNodeList firstLevelNodeList = rootNode.ChildNodes;
|
|
|
|
|
|
foreach (XmlNode node in firstLevelNodeList)
|
|
|
|
|
|
{
|
|
|
|
|
|
//修改此节点的属性值
|
|
|
|
|
|
if (node.Attributes["Description"].Value.Equals("Made in USA"))
|
|
|
|
|
|
{
|
|
|
|
|
|
node.Attributes["Description"].Value = "Made in HongKong";
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
//要想使对xml文件所做的修改生效,必须执行以下Save方法
|
|
|
|
|
|
myXmlDoc.Save(xmlFilePath);
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
Console.WriteLine(ex.ToString());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void AddXmlInformation(string xmlFilePath)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
XmlDocument myXmlDoc = new XmlDocument();
|
|
|
|
|
|
myXmlDoc.Load(xmlFilePath);
|
|
|
|
|
|
//添加一个带有属性的节点信息
|
|
|
|
|
|
foreach (XmlNode node in myXmlDoc.FirstChild.ChildNodes)
|
|
|
|
|
|
{
|
|
|
|
|
|
XmlElement newElement = myXmlDoc.CreateElement("color");
|
|
|
|
|
|
newElement.InnerText = "black";
|
|
|
|
|
|
newElement.SetAttribute("IsMixed", "Yes");
|
|
|
|
|
|
node.AppendChild(newElement);
|
|
|
|
|
|
}
|
|
|
|
|
|
//保存更改
|
|
|
|
|
|
myXmlDoc.Save(xmlFilePath);
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
Console.WriteLine(ex.ToString());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void DeleteXmlInformation(string xmlFilePath)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
XmlDocument myXmlDoc = new XmlDocument();
|
|
|
|
|
|
myXmlDoc.Load(xmlFilePath);
|
|
|
|
|
|
foreach (XmlNode node in myXmlDoc.FirstChild.ChildNodes)
|
|
|
|
|
|
{
|
|
|
|
|
|
//记录该节点下的最后一个子节点(简称:最后子节点)
|
|
|
|
|
|
XmlNode lastNode = node.LastChild;
|
|
|
|
|
|
//删除最后子节点下的左右子节点
|
|
|
|
|
|
lastNode.RemoveAll();
|
|
|
|
|
|
//删除最后子节点
|
|
|
|
|
|
node.RemoveChild(lastNode);
|
|
|
|
|
|
}
|
|
|
|
|
|
//保存对xml文件所做的修改
|
|
|
|
|
|
myXmlDoc.Save(xmlFilePath);
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
Console.WriteLine(ex.ToString());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//文件复制实现:https://www.cnblogs.com/sun-shadow/p/7553556.html
|
2022-06-16 13:26:55 +08:00
|
|
|
|
public bool CopyFiles2Project(string sourceFolderName, ref int fileCounter)//
|
2021-12-14 18:39:55 +08:00
|
|
|
|
{
|
|
|
|
|
|
if (Directory.Exists(mRawPath))
|
|
|
|
|
|
{
|
|
|
|
|
|
DelectDir(mRawPath);
|
|
|
|
|
|
}
|
2022-06-16 13:26:55 +08:00
|
|
|
|
|
|
|
|
|
|
bool re = CopySubFun2(sourceFolderName, mRawPath, true, ref mCsvFileCount);//因为此函数会递归,所以把它摘出来
|
|
|
|
|
|
|
|
|
|
|
|
return re;
|
2022-01-14 11:56:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-06-16 13:26:55 +08:00
|
|
|
|
public bool CopyCalFiles2Project(string sourceFolderName)
|
2022-01-14 11:56:12 +08:00
|
|
|
|
{
|
|
|
|
|
|
if (!Directory.Exists(sourceFolderName))
|
|
|
|
|
|
{
|
2022-06-16 13:26:55 +08:00
|
|
|
|
return false;
|
2022-01-14 11:56:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
if (!Directory.Exists(mMetadataPath))
|
|
|
|
|
|
{
|
|
|
|
|
|
Directory.CreateDirectory(mMetadataPath);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
string[] sourceFilesPath = Directory.GetFileSystemEntries(sourceFolderName);
|
|
|
|
|
|
|
2022-06-16 13:26:55 +08:00
|
|
|
|
int fileCounterCopied = 0;
|
2022-01-14 11:56:12 +08:00
|
|
|
|
for (int i = 0; i < sourceFilesPath.Length; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
string sourceFilePath = sourceFilesPath[i];
|
|
|
|
|
|
string[] forlders = sourceFilePath.Split('\\');
|
|
|
|
|
|
|
|
|
|
|
|
if (File.Exists(sourceFilePath))//是文件,直接拷贝
|
|
|
|
|
|
{
|
|
|
|
|
|
string dest = mMetadataPath;
|
|
|
|
|
|
string sourceFileName = Path.GetFileName(sourceFilePath);//获取文件名
|
|
|
|
|
|
File.Copy(sourceFilePath, Path.Combine(dest, sourceFileName), true);
|
|
|
|
|
|
|
2022-06-16 13:26:55 +08:00
|
|
|
|
fileCounterCopied++;
|
2022-01-14 11:56:12 +08:00
|
|
|
|
}
|
2022-06-16 13:26:55 +08:00
|
|
|
|
//因为定标文件不能够放在
|
|
|
|
|
|
//else if (Directory.Exists(sourceFilePath))//是文件夹,拷贝文件夹;并递归
|
|
|
|
|
|
//{
|
|
|
|
|
|
// string lastDirectory = forlders[forlders.Length - 1];
|
|
|
|
|
|
// string dest = Path.Combine(mMetadataPath, lastDirectory);
|
|
|
|
|
|
|
|
|
|
|
|
// if (!Directory.Exists(dest))
|
|
|
|
|
|
// {
|
|
|
|
|
|
// Directory.CreateDirectory(dest);
|
|
|
|
|
|
// }
|
|
|
|
|
|
// CopySubFun(sourceFilePath, dest, true);
|
|
|
|
|
|
//}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (fileCounterCopied == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
2022-01-14 11:56:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-06-16 13:26:55 +08:00
|
|
|
|
return true;
|
2021-12-14 18:39:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-06-16 13:26:55 +08:00
|
|
|
|
private bool CopySubFun(string sourceFolderName, string destFolderName, bool overwrite)//因为此函数会递归,所以把它摘出来
|
2021-12-14 18:39:55 +08:00
|
|
|
|
{
|
|
|
|
|
|
if (!Directory.Exists(sourceFolderName))
|
|
|
|
|
|
{
|
2022-06-16 13:26:55 +08:00
|
|
|
|
return false;
|
2021-12-14 18:39:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
if (!Directory.Exists(destFolderName))
|
|
|
|
|
|
{
|
|
|
|
|
|
Directory.CreateDirectory(destFolderName);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
string[] sourceFilesPath = Directory.GetFileSystemEntries(sourceFolderName);
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < sourceFilesPath.Length; i++)
|
|
|
|
|
|
{
|
2021-12-16 18:40:51 +08:00
|
|
|
|
string sourceFilePath = sourceFilesPath[i];
|
|
|
|
|
|
string[] forlders = sourceFilePath.Split('\\');
|
2021-12-14 18:39:55 +08:00
|
|
|
|
|
|
|
|
|
|
if (File.Exists(sourceFilePath))//是文件,直接拷贝
|
|
|
|
|
|
{
|
|
|
|
|
|
string dest = destFolderName;
|
2021-12-16 18:40:51 +08:00
|
|
|
|
string sourceFileName = Path.GetFileName(sourceFilePath);//获取文件名
|
2021-12-14 18:39:55 +08:00
|
|
|
|
File.Copy(sourceFilePath, Path.Combine(dest, sourceFileName), overwrite);
|
2022-01-14 11:56:12 +08:00
|
|
|
|
|
|
|
|
|
|
//统计文件个数
|
|
|
|
|
|
mCsvFileCount++;
|
2021-12-14 18:39:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
else if (Directory.Exists(sourceFilePath))//是文件夹,拷贝文件夹;并递归
|
|
|
|
|
|
{
|
|
|
|
|
|
string lastDirectory = forlders[forlders.Length - 1];
|
2021-12-16 18:40:51 +08:00
|
|
|
|
string dest = Path.Combine(destFolderName, lastDirectory);
|
2021-12-14 18:39:55 +08:00
|
|
|
|
|
|
|
|
|
|
if (!Directory.Exists(dest))
|
|
|
|
|
|
{
|
|
|
|
|
|
Directory.CreateDirectory(dest);
|
|
|
|
|
|
}
|
|
|
|
|
|
CopySubFun(sourceFilePath, dest, overwrite);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-06-16 13:26:55 +08:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
2022-01-14 11:56:12 +08:00
|
|
|
|
|
2022-06-16 13:26:55 +08:00
|
|
|
|
private bool CopySubFun2(string sourceFolderName, string destFolderName, bool overwrite, ref int fileCounter)//不使用递归
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!Directory.Exists(sourceFolderName))
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!Directory.Exists(destFolderName))
|
|
|
|
|
|
{
|
|
|
|
|
|
Directory.CreateDirectory(destFolderName);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
string[] files = Directory.GetFiles(sourceFolderName);
|
|
|
|
|
|
if (files.Length>0)
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
string[] sourceForldersPath = Directory.GetFileSystemEntries(sourceFolderName);
|
|
|
|
|
|
for (int i = 0; i < sourceForldersPath.Length; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
string sourceForlder = sourceForldersPath[i];
|
|
|
|
|
|
|
|
|
|
|
|
string[] forlders = sourceForlder.Split('\\');
|
|
|
|
|
|
string destFolderName2 = Path.Combine(destFolderName, forlders[forlders.Length - 1]);
|
|
|
|
|
|
|
|
|
|
|
|
if (File.Exists(sourceForlder))//如果是文件,代表用户选择的dn数据文件夹结构有问题
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!Directory.Exists(destFolderName2))
|
|
|
|
|
|
{
|
|
|
|
|
|
Directory.CreateDirectory(destFolderName2);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
string[] filesPath = Directory.GetFileSystemEntries(sourceForlder);
|
|
|
|
|
|
for (int j = 0; j < filesPath.Length; j++)//必须按照源文件夹结构!!!!!!
|
|
|
|
|
|
{
|
|
|
|
|
|
string filePath = filesPath[j];
|
|
|
|
|
|
if (Directory.Exists(filePath))//如果是文件夹,代表用户选择的dn数据文件夹结构有问题
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
string sourceFileName = Path.GetFileName(filePath);//获取文件名
|
|
|
|
|
|
File.Copy(filePath, Path.Combine(destFolderName2, sourceFileName), overwrite);
|
|
|
|
|
|
|
|
|
|
|
|
//统计文件个数
|
|
|
|
|
|
fileCounter++;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (fileCounter == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
2021-12-14 18:39:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-03-15 10:19:53 +08:00
|
|
|
|
public void DelectDir(string srcPath)
|
2021-12-14 18:39:55 +08:00
|
|
|
|
{
|
|
|
|
|
|
DirectoryInfo dir = new DirectoryInfo(srcPath);
|
|
|
|
|
|
FileSystemInfo[] fileinfo = dir.GetFileSystemInfos(); //返回目录中所有文件和子目录
|
|
|
|
|
|
foreach (FileSystemInfo i in fileinfo)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (i is DirectoryInfo) //判断是否文件夹
|
|
|
|
|
|
{
|
|
|
|
|
|
DirectoryInfo subdir = new DirectoryInfo(i.FullName);
|
|
|
|
|
|
subdir.Delete(true); //删除子目录和文件
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
File.Delete(i.FullName); //删除指定文件
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-03-15 10:19:53 +08:00
|
|
|
|
public void DelectDirIncludeItself(string srcPath)
|
|
|
|
|
|
{
|
|
|
|
|
|
DirectoryInfo dir = new DirectoryInfo(srcPath);
|
|
|
|
|
|
dir.Delete(true);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-12-14 18:39:55 +08:00
|
|
|
|
|
|
|
|
|
|
//工程结构
|
|
|
|
|
|
public void CreateProjectStructure()
|
|
|
|
|
|
{
|
|
|
|
|
|
//创建工程文件夹结构
|
2021-12-16 18:40:51 +08:00
|
|
|
|
//mMetadataPath = mProjectPath + "\\.project\\";
|
|
|
|
|
|
//mRawPath = mProjectPath + "\\1raw\\";
|
|
|
|
|
|
//mRadPath = mProjectPath + "\\2rad\\";
|
|
|
|
|
|
//mSifPath = mProjectPath + "\\3sif\\";
|
|
|
|
|
|
|
|
|
|
|
|
mMetadataPath = Path.Combine(mProjectPath, ".project");
|
|
|
|
|
|
mRawPath = Path.Combine(mProjectPath, "1raw");
|
|
|
|
|
|
mRadPath = Path.Combine(mProjectPath, "2rad");
|
|
|
|
|
|
mSifPath = Path.Combine(mProjectPath, "3sif");
|
|
|
|
|
|
|
|
|
|
|
|
if (false == Directory.Exists(mMetadataPath))
|
|
|
|
|
|
{
|
|
|
|
|
|
Directory.CreateDirectory(mMetadataPath);
|
|
|
|
|
|
}
|
2021-12-14 18:39:55 +08:00
|
|
|
|
if (false == Directory.Exists(mRawPath))
|
|
|
|
|
|
{
|
|
|
|
|
|
Directory.CreateDirectory(mRawPath);
|
|
|
|
|
|
}
|
|
|
|
|
|
if (false == Directory.Exists(mRadPath))
|
|
|
|
|
|
{
|
|
|
|
|
|
Directory.CreateDirectory(mRadPath);
|
|
|
|
|
|
}
|
|
|
|
|
|
if (false == Directory.Exists(mSifPath))
|
|
|
|
|
|
{
|
|
|
|
|
|
Directory.CreateDirectory(mSifPath);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2021-12-16 18:40:51 +08:00
|
|
|
|
|
|
|
|
|
|
|
2022-03-15 10:19:53 +08:00
|
|
|
|
//如果一个委托不需要再其定义的类之外被触发,那么就可以将其转化为事件,这样可以保证它不会在外部被随意触发。
|
2022-07-06 13:40:16 +08:00
|
|
|
|
public event RadPercentCompleteDelegate UpdateProgressBarInfoEvent;//申明事件
|
2022-03-15 10:19:53 +08:00
|
|
|
|
public event RadCompleteDelegate RadCompleteEvent;//申明委托变量
|
2022-01-14 11:56:12 +08:00
|
|
|
|
|
2022-07-06 13:40:16 +08:00
|
|
|
|
private void EventRelay(int ipos, string vinfo)
|
|
|
|
|
|
{
|
|
|
|
|
|
UpdateProgressBarInfoEvent(ipos, vinfo);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-12-16 18:40:51 +08:00
|
|
|
|
//处理工程中的数据
|
|
|
|
|
|
public void Rad()
|
|
|
|
|
|
{
|
2021-12-22 18:07:40 +08:00
|
|
|
|
//读取标定文件:辐射定标文件 + 非线性校正文件
|
2022-07-06 13:40:16 +08:00
|
|
|
|
CalData[] calDatas;
|
|
|
|
|
|
NonLinearData[] nonLinearDatas;
|
|
|
|
|
|
calAndNonLinearFileReader.readCalAndNonLinearFile(mMetadataPath, out calDatas, out nonLinearDatas);
|
2021-12-20 18:34:41 +08:00
|
|
|
|
|
2021-12-22 18:07:40 +08:00
|
|
|
|
//对文件夹中的文件遍历处理:非线性校正 + 辐射定标
|
2022-07-06 13:40:16 +08:00
|
|
|
|
SpectralProcessor sp = new SpectralProcessor();
|
|
|
|
|
|
sp.RadPercentCompleteEvent += EventRelay;
|
|
|
|
|
|
sp.processDirectory_dn2rad(mRawPath, mRadPath, calDatas, nonLinearDatas, true, mCsvFileCount);
|
2022-03-15 10:19:53 +08:00
|
|
|
|
|
|
|
|
|
|
if (RadCompleteEvent != null)//确认事件有方法可以执行
|
|
|
|
|
|
{
|
|
|
|
|
|
RadCompleteEvent();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-12-22 18:07:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-01-14 11:56:12 +08:00
|
|
|
|
DateFolder[] df;
|
|
|
|
|
|
public void FindTimespan()//因为此函数会递归,所以把它摘出来
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!Directory.Exists(mRadPath))
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
string[] dateFolders = Directory.GetFileSystemEntries(mRadPath);
|
|
|
|
|
|
|
|
|
|
|
|
df = new DateFolder[dateFolders.Length];
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < dateFolders.Length; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
string dateFolder = dateFolders[i];
|
|
|
|
|
|
|
|
|
|
|
|
if (Directory.Exists(dateFolder))//是文件夹
|
|
|
|
|
|
{
|
|
|
|
|
|
string[] splitPath = dateFolder.Split('\\');//
|
|
|
|
|
|
string lastDirectory = splitPath[splitPath.Length - 1];
|
|
|
|
|
|
|
|
|
|
|
|
df[i] = new DateFolder(lastDirectory);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Array.Sort(df);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-06-16 13:26:55 +08:00
|
|
|
|
public int GetDateFolderCount()
|
|
|
|
|
|
{
|
|
|
|
|
|
FindTimespan();
|
|
|
|
|
|
return df.Length;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-01-14 11:56:12 +08:00
|
|
|
|
public string GetMinDate()
|
|
|
|
|
|
{
|
2022-06-16 13:26:55 +08:00
|
|
|
|
if (df.Length == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
return df[0].mDateFolder;
|
|
|
|
|
|
}
|
2022-01-14 11:56:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public string GetMaxDate()
|
|
|
|
|
|
{
|
2022-06-16 13:26:55 +08:00
|
|
|
|
if (df.Length == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
return df[df.Length - 1].mDateFolder;
|
|
|
|
|
|
}
|
2022-01-14 11:56:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void CopyWantedFiles(string minTime, string maxTime)
|
|
|
|
|
|
{
|
|
|
|
|
|
mSifTmpPath = Path.Combine(mProjectPath, "sifTmp");//mSifTmpPath
|
|
|
|
|
|
|
|
|
|
|
|
if (false == Directory.Exists(mSifTmpPath))
|
|
|
|
|
|
{
|
|
|
|
|
|
Directory.CreateDirectory(mSifTmpPath);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DelectDir(mSifTmpPath);//删除文件夹中的内容
|
|
|
|
|
|
|
|
|
|
|
|
//遍历,复制文件夹[minTime,maxTime]中的文件到mSifTmpPath
|
|
|
|
|
|
DateFolder minDateFolder = new DateFolder(minTime);
|
|
|
|
|
|
DateFolder maxDateFolder = new DateFolder(maxTime);
|
|
|
|
|
|
foreach (DateFolder currentFolder in df)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (minDateFolder > currentFolder | currentFolder > maxDateFolder)
|
|
|
|
|
|
{
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//复制文件
|
|
|
|
|
|
string sourcePath = Path.Combine(mRadPath, currentFolder.mDateFolder);
|
|
|
|
|
|
|
|
|
|
|
|
CopyWithModifyName(sourcePath, mSifTmpPath, true);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void CopyWithModifyName(string sourceFolderPath, string destFolderPath, bool overwrite)//
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!Directory.Exists(sourceFolderPath))
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!Directory.Exists(destFolderPath))
|
|
|
|
|
|
{
|
|
|
|
|
|
Directory.CreateDirectory(destFolderPath);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
string[] sourceFilesPath = Directory.GetFileSystemEntries(sourceFolderPath);
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < sourceFilesPath.Length; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
string sourceFilePath = sourceFilesPath[i];
|
|
|
|
|
|
|
|
|
|
|
|
//构建文件名
|
|
|
|
|
|
string destFileName="";
|
|
|
|
|
|
string[] forlders = sourceFilePath.Split('\\');
|
|
|
|
|
|
|
|
|
|
|
|
string sourceFolderName = forlders[forlders.Length - 2];//获取文件所在目录的目录名
|
|
|
|
|
|
string sourceFileName = forlders[forlders.Length - 1];//获取文件名sourceFileName
|
|
|
|
|
|
//string sourceFileName = Path.GetFileName(sourceFilePath);
|
|
|
|
|
|
|
|
|
|
|
|
int firstIndex = sourceFileName.IndexOf("_");
|
|
|
|
|
|
int lastIndex = sourceFileName.LastIndexOf("_");
|
|
|
|
|
|
if (firstIndex != -1)
|
|
|
|
|
|
{
|
|
|
|
|
|
destFileName = sourceFileName.Substring(firstIndex);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (File.Exists(sourceFilePath))//是文件,直接拷贝
|
|
|
|
|
|
{
|
|
|
|
|
|
File.Copy(sourceFilePath, Path.Combine(destFolderPath, sourceFolderName + destFileName), overwrite);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-12-14 18:39:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|