|
@@ -89,8 +89,8 @@ namespace FileWatcher
|
|
|
FormBorderStyle = FormBorderStyle.FixedSingle;
|
|
|
InitDB = new Thread(ConnectDB);
|
|
|
//添加监控事件
|
|
|
- XmlWatcher.Created += new FileSystemEventHandler(XmlWatcher_Created);
|
|
|
XmlWatcher.Changed += new FileSystemEventHandler(XmlWatcher_Created);
|
|
|
+ ATEFile.Created += new FileSystemEventHandler(XmlWatcher_Created);
|
|
|
SetLoadingWindow stw = new SetLoadingWindow(InitDB, "正在启动程序");
|
|
|
stw.StartPosition = FormStartPosition.CenterScreen;
|
|
|
stw.ShowDialog();
|
|
@@ -105,7 +105,8 @@ namespace FileWatcher
|
|
|
//获取缓存信息
|
|
|
try
|
|
|
{
|
|
|
- //FolderPath.Text = BaseUtil.GetCacheData("FolderPath").ToString();
|
|
|
+ FolderPath.Text = BaseUtil.GetCacheData("FolderPath").ToString();
|
|
|
+ Device.Text = BaseUtil.GetCacheData("Device").ToString();
|
|
|
//BackUpFolderPath.Text = BaseUtil.GetCacheData("BackUpFolderPath").ToString();
|
|
|
//Master.Text = BaseUtil.GetCacheData("Master").ToString();
|
|
|
//AutoStart.Checked = (bool)BaseUtil.GetCacheData("AutoStart");
|
|
@@ -123,7 +124,7 @@ namespace FileWatcher
|
|
|
|
|
|
private void ConnectDB()
|
|
|
{
|
|
|
- DataHelper.DBConnectionString = "Connection Timeout=0;Pooling=false;Password=select!#%*(;User ID=N_MES;Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.101.253)(PORT=11678)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
|
|
|
+ DataHelper.DBConnectionString = "Connection Timeout=0;Pooling=false;Password=select!#%*(;User ID=N_MES;Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.6.253)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
|
|
|
dh = new DataHelper();
|
|
|
}
|
|
|
|
|
@@ -143,10 +144,15 @@ namespace FileWatcher
|
|
|
}
|
|
|
}
|
|
|
XmlWatcher.Path = FolderPath.Text;
|
|
|
- XmlWatcher.Filter = "*.log|*.ini";
|
|
|
XmlWatcher.EnableRaisingEvents = true;
|
|
|
+ XmlWatcher.NotifyFilter = NotifyFilters.FileName | NotifyFilters.LastWrite;
|
|
|
+ ATEFile.Path = FolderPath.Text;
|
|
|
+ ATEFile.EnableRaisingEvents = true;
|
|
|
+ ATEFile.NotifyFilter = NotifyFilters.FileName | NotifyFilters.LastWrite;
|
|
|
//设置缓存数据
|
|
|
- //BaseUtil.SetCacheData("FolderPath", FolderPath.Text);
|
|
|
+ BaseUtil.SetCacheData("FolderPath", FolderPath.Text);
|
|
|
+ BaseUtil.SetCacheData("Device", Device.Text);
|
|
|
+
|
|
|
//BaseUtil.SetCacheData("BackUpFolderPath", BackUpFolderPath.Text);
|
|
|
//BaseUtil.SetCacheData("Master", Master.Text);
|
|
|
//BaseUtil.SetCacheData("AutoStart", AutoStart.Checked);
|
|
@@ -161,17 +167,12 @@ namespace FileWatcher
|
|
|
OperateResult.AppendText("开始执行监控\n");
|
|
|
}
|
|
|
|
|
|
- public void CreateNode(XmlDocument xmlDoc, XmlNode parentNode, string name, string value)
|
|
|
- {
|
|
|
- XmlNode node = xmlDoc.CreateNode(XmlNodeType.Element, name, null);
|
|
|
- node.InnerText = value;
|
|
|
- parentNode.AppendChild(node);
|
|
|
- }
|
|
|
-
|
|
|
private void XmlWatcher_Created(object sender, FileSystemEventArgs e)
|
|
|
{
|
|
|
-
|
|
|
+ OperateResult.AppendText("文件修改:" + e.FullPath + "\n");
|
|
|
+ TxtHandleProcess(e.FullPath);
|
|
|
}
|
|
|
+
|
|
|
string nextLine;
|
|
|
private void TxtHandleProcess(string FileName)
|
|
|
{
|
|
@@ -180,7 +181,8 @@ namespace FileWatcher
|
|
|
List<string> badprod = new List<string>();
|
|
|
if (Device.Text == "老化设备")
|
|
|
{
|
|
|
- StreamReader sR = File.OpenText(FileName);
|
|
|
+ StreamReader sR = new StreamReader(FileName, Encoding.Default);
|
|
|
+ Console.WriteLine(sR.CurrentEncoding);
|
|
|
DataTable filedt = new DataTable();
|
|
|
//文件内的行,用一个DataTable存储
|
|
|
int Rowindex = 0;
|
|
@@ -229,13 +231,27 @@ namespace FileWatcher
|
|
|
Rowindex = Rowindex + 1;
|
|
|
}
|
|
|
sR.Close();
|
|
|
+ OperateResult.AppendText("文件修改" + filedt.Rows.Count + "\n");
|
|
|
for (int i = 0; i < filedt.Rows.Count; i++)
|
|
|
{
|
|
|
- string filename = filedt.Rows[i]["文件路径"].ToString();
|
|
|
- string ftppath = "/" + DateTime.Now.ToString("yyyy-MM-dd") + "/";
|
|
|
- string folderpath = filename.Substring(0, filename.LastIndexOf(@"\"));
|
|
|
- ftp.UpLoadFile(folderpath, filename, ftppath, "");
|
|
|
- dh.ExecuteSql("insert into Devicetestinfo(dti_id,dti_prodcode,dti_area,dti_uptime,dti_downtime,dti_upqty,dti_okqty,dti_ngqty,dti_ipaddress,dti_filepath,dti_indate)values(Devicetestinfo_seq.nextval,'" + filedt.Rows[i]["产品代码"].ToString() + "','" + filedt.Rows[i]["区域"].ToString() + "',to_date('" + filedt.Rows[i]["上架时间"].ToString() + "','yyyy/mm/dd hh24:mi:ss'),to_date('" + filedt.Rows[i]["下架时间"].ToString() + "','yyyy/mm/dd hh24:mi:ss'),'" + filedt.Rows[i]["上架数量"].ToString() + "','" + filedt.Rows[i]["合格数量"].ToString() + "','" + filedt.Rows[i]["不良数量"].ToString() + "','" + IPAddress + "','http://192.168.6.253:8099/ftp" + ftppath + filename + "',sysdate)", "insert");
|
|
|
+ if (!dh.CheckExist("Devicetestinfo", "(dti_uptime)=to_date('" + filedt.Rows[i]["上架时间"].ToString() + "','yyyy/mm/dd hh24:mi:ss') and dti_ipaddress='" + IPAddress + "'"))
|
|
|
+ {
|
|
|
+ string filename = filedt.Rows[i]["文件路径"].ToString();
|
|
|
+ string ftppath = "/AGING/" + DateTime.Now.ToString("yyyy") + "/" + DateTime.Now.ToString("yyyy-MM") + "/" + DateTime.Now.ToString("MM-dd") + "/";
|
|
|
+ string folderpath = filename.Substring(0, filename.LastIndexOf(@"\"));
|
|
|
+ //ftp.UpLoadFile(folderpath, filename.Substring(filename.LastIndexOf(@"\")), ftppath, "");
|
|
|
+ Dictionary<string, object> dic = new Dictionary<string, object>();
|
|
|
+ dic.Add("em_name", "管理员");
|
|
|
+ dic.Add("em_code", "ADMIN");
|
|
|
+ dic.Add("caller", "AGING");
|
|
|
+ string fp_id;
|
|
|
+ string fp_path;
|
|
|
+ UploadFilesToRemoteUrl("http://192.168.199.173:8080/mes/MEScommon/uploadFiles.action?_noc=1", filename, dic,out fp_path, out fp_id);
|
|
|
+ fp_path = "http://192.168.199.173:8080/" + fp_path.Replace("/app/uas/webapps/", "");
|
|
|
+ fp_path= fp_path.Replace("\"","");
|
|
|
+ dh.ExecuteSql("insert into Devicetestinfo(dti_id,dti_prodcode,dti_area,dti_uptime,dti_downtime,dti_upqty,dti_okqty,dti_ngqty,dti_ipaddress,dti_filepath,dti_indate,dti_fpid)values(Devicetestinfo_seq.nextval,'" + filedt.Rows[i]["产品代码"].ToString() + "','" + filedt.Rows[i]["区域"].ToString() + "',to_date('" + filedt.Rows[i]["上架时间"].ToString() + "','yyyy/mm/dd hh24:mi:ss'),to_date('" + filedt.Rows[i]["下架时间"].ToString() + "','yyyy/mm/dd hh24:mi:ss'),'" + filedt.Rows[i]["上架数量"].ToString() + "','" + filedt.Rows[i]["合格数量"].ToString() + "','" + filedt.Rows[i]["不良数量"].ToString() + "','" + IPAddress + "','"+ fp_path + "',sysdate,'"+ fp_id + "')", "insert");
|
|
|
+ OperateResult.AppendText("上传文件" + filename + "\n");
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
else if (Device.Text == "ATE设备")
|
|
@@ -352,23 +368,117 @@ namespace FileWatcher
|
|
|
}
|
|
|
|
|
|
private void BatchAnalysus_Click(object sender, EventArgs e)
|
|
|
+ {
|
|
|
+ TxtHandleProcess(@"C:\Users\callm\Desktop\导入数据\客户资料\睿德电子\新建文本文档.log");
|
|
|
+ //TxtHandleProcess(@"C:\Users\callm\Desktop\导入数据\客户资料\睿德电子\PowerTestTj.ini");
|
|
|
+ }
|
|
|
+
|
|
|
+ private void Timer_Tick(object sender, EventArgs e)
|
|
|
{
|
|
|
//var AllXmls = Directory.GetFiles(FolderPath.Text, "*.txt");
|
|
|
//foreach (var Xml in AllXmls)
|
|
|
//{
|
|
|
// TxtHandleProcess(Xml);
|
|
|
//}
|
|
|
- //TxtHandleProcess(@"C:\Users\callm\Desktop\客户资料\睿德电子\新建文本文档.log");
|
|
|
- TxtHandleProcess(@"C:\Users\callm\Desktop\客户资料\睿德电子\PowerTestTj.ini");
|
|
|
}
|
|
|
|
|
|
- private void Timer_Tick(object sender, EventArgs e)
|
|
|
+ /// <summary>
|
|
|
+ /// 请求上传图片到阿里云
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="url">上传地址</param>
|
|
|
+ /// <param name="filepath">本地文件路径</param>
|
|
|
+ /// <param name="dic">上传的数据信息</param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public string UploadFilesToRemoteUrl(string url1, string filepath, Dictionary<string, object> dic,out string fp_path,out string fp_id)
|
|
|
{
|
|
|
- var AllXmls = Directory.GetFiles(FolderPath.Text, "*.txt");
|
|
|
- foreach (var Xml in AllXmls)
|
|
|
+ fp_id = "";
|
|
|
+ fp_path = "";
|
|
|
+ try
|
|
|
+ {
|
|
|
+ ServicePointManager.DefaultConnectionLimit = 50;
|
|
|
+
|
|
|
+ string boundary = DateTime.Now.Ticks.ToString("x");
|
|
|
+
|
|
|
+ byte[] boundarybytes = System.Text.Encoding.UTF8.GetBytes("--" + boundary + "\r\n");
|
|
|
+
|
|
|
+ HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url1);
|
|
|
+ request.Method = "POST";
|
|
|
+ request.Timeout = 10 * 10000;
|
|
|
+ request.ContentType = "multipart/form-data; boundary=" + boundary;
|
|
|
+
|
|
|
+ Stream rs = request.GetRequestStream();
|
|
|
+
|
|
|
+ var endBoundaryBytes = Encoding.UTF8.GetBytes("--" + boundary + "--\r\n");
|
|
|
+
|
|
|
+ string formdataTemplate = "Content-Disposition: form-data; name=\"{0}\"\r\n" + "\r\n" + "{1}" + "\r\n";
|
|
|
+ if (dic != null)
|
|
|
+ {
|
|
|
+ foreach (string key in dic.Keys)
|
|
|
+ {
|
|
|
+ rs.Write(boundarybytes, 0, boundarybytes.Length);
|
|
|
+
|
|
|
+ string formitem = string.Format(formdataTemplate, key, dic[key]);
|
|
|
+
|
|
|
+ byte[] formitembytes = System.Text.Encoding.UTF8.GetBytes(formitem);
|
|
|
+
|
|
|
+ rs.Write(formitembytes, 0, formitembytes.Length);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ string headerTemplate = "Content-Disposition: form-data; name=\"{0}\"; filename=\"{1}\"\r\n\r\n";
|
|
|
+ {
|
|
|
+ rs.Write(boundarybytes, 0, boundarybytes.Length);
|
|
|
+
|
|
|
+ var header = string.Format(headerTemplate, "file", Path.GetFileName(filepath));
|
|
|
+
|
|
|
+ var headerbytes = System.Text.Encoding.UTF8.GetBytes(header);
|
|
|
+
|
|
|
+ rs.Write(headerbytes, 0, headerbytes.Length);
|
|
|
+
|
|
|
+ using (var fileStream = new FileStream(filepath, FileMode.Open, FileAccess.Read))
|
|
|
+ {
|
|
|
+ var buffer = new byte[1024];
|
|
|
+
|
|
|
+ var bytesRead = 0;
|
|
|
+
|
|
|
+ while ((bytesRead = fileStream.Read(buffer, 0, buffer.Length)) != 0)
|
|
|
+ {
|
|
|
+ rs.Write(buffer, 0, bytesRead);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ var cr = Encoding.UTF8.GetBytes("\r\n");
|
|
|
+
|
|
|
+ rs.Write(cr, 0, cr.Length);
|
|
|
+ }
|
|
|
+
|
|
|
+ rs.Write(endBoundaryBytes, 0, endBoundaryBytes.Length);
|
|
|
+
|
|
|
+ var response = request.GetResponse() as HttpWebResponse;
|
|
|
+
|
|
|
+ StreamReader newReader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
|
|
|
+ string Content = newReader.ReadToEnd();
|
|
|
+ Dictionary<string, object> dic1 = new Dictionary<string, object>();
|
|
|
+ List<Dictionary<string, object>> dic2 = null;
|
|
|
+ dic1 = BaseUtil.ToDictionary(Content);
|
|
|
+ dic2 = dic1["data"] as List<Dictionary<string, object>>;
|
|
|
+
|
|
|
+ if (dic2[0]["filepath"] != null)
|
|
|
+ {
|
|
|
+ fp_id = dic2[0]["filepath"].ToString();
|
|
|
+ fp_path= dic2[0]["path"].ToString();
|
|
|
+ }
|
|
|
+ if (response.StatusCode == HttpStatusCode.OK)
|
|
|
+ {
|
|
|
+ Console.WriteLine(fp_id);
|
|
|
+ return fp_id;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception e)
|
|
|
{
|
|
|
- TxtHandleProcess(Xml);
|
|
|
+ Console.WriteLine(e.Message + e.StackTrace);
|
|
|
}
|
|
|
+ return "";
|
|
|
}
|
|
|
}
|
|
|
}
|