public static void CreateStatecFile(LotEntity lotEntity, string localdir, string infofile, string station) { UtilLog.Info("starting Create statec file:"); string date = System.DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss"); string filename = localdir + "\\" + infofile; string cmd = "shellnt program " + lotEntity.RecipeName + " -at -b"; try { DeleteFile(localdir, infofile.Substring(infofile.Length - 4, 4)); StreamWriter sw = File.CreateText(filename); sw.WriteLine("STATION:" + station); sw.WriteLine("DEVICE_NAME:" + lotEntity.DeviceId); sw.WriteLine("PROGRAM_NAME:" + lotEntity.RecipeName); sw.WriteLine("LOT_NUMBER:" + lotEntity.LotNo); sw.WriteLine("LOT_QUANTITY:" + lotEntity.LotQty); sw.WriteLine("GDCAL:" + lotEntity.SpmGdcal); sw.Flush(); sw.Close(); } catch (Exception ex) { UtilLog.Error(ex); } }
public static void CreateEagleFile(LotEntity lotEntity, string localdir, string infofile) { string date = System.DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss"); string filename = localdir + "\\" + infofile; string cmd = "shellnt program " + lotEntity.RecipeName + " -at -b"; try { StreamWriter sw = File.CreateText(filename); sw.WriteLine("Time=" + date + "\n"); sw.WriteLine("Product=" + lotEntity.DeviceId + "\n"); sw.WriteLine("RecipeName =" + lotEntity.RecipeName + "\n"); sw.WriteLine("LotNo =" + lotEntity.LotNo + "\n"); sw.WriteLine("SubLotNo = 1" + "\n"); sw.WriteLine("LotSize = " + lotEntity.LotQty + "\n"); sw.Flush(); sw.Close(); StartCommand(cmd); date = System.DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss"); System.Text.StringBuilder strMsg = new System.Text.StringBuilder("Time=" + date + "\r\n"); strMsg.Append("Product=" + lotEntity.DeviceId + "\r\n"); strMsg.Append("shellnt program " + lotEntity.RecipeName + " -at -b"); } catch (Exception ex) { UtilLog.Error(ex); } }
public static void DeleteFile(string localDir, string type) { DirectoryInfo di = new DirectoryInfo(@localDir); FileInfo[] ff = di.GetFiles(type); try { if (ff.Length != 0) { foreach (FileInfo fi in ff) { fi.Delete(); } } } catch (Exception ex) { UtilLog.Error(ex); } }
public static void MoveFile(string fullpath, string fileName, string destdir) { try { if (!Directory.Exists(destdir)) { Directory.CreateDirectory(destdir); } string destpath = destdir + fileName; //目标路径 if (File.Exists(destpath)) { File.Delete(destpath); //目标目录中有此文件,则先删除,再移过来。 } File.Move(fullpath, destpath); UtilLog.Info("Move file: " + fullpath + " to path: " + destdir); } catch (Exception ex) { UtilLog.Error("Handle Move File Err:", ex); } }
public static bool CopyFile(string fullpath, string fileName, string destdir) { try { if (!Directory.Exists(destdir)) { Directory.CreateDirectory(destdir); } string destpath = destdir + fileName; //目标路径 if (File.Exists(destpath)) { File.Delete(destpath); //目标目录中有此文件,则先删除,再移过来。 } File.Copy(fullpath, destpath); return(true); } catch (Exception ex) { UtilLog.Error("Handle Copy File Err:", ex); return(false); } }
public static string DownloadRecipe(string ftpuri, string DownloadDir, string ext) { string uri = ftpuri.Split(',')[0]; string ftpUserID = ftpuri.Split(',')[1]; string ftpPassword = ftpuri.Split(',')[2]; string fileName = uri.Replace("/", "@").Split('@')[4].ToString() + "." + ext; uri = uri + "." + ext; FtpWebRequest reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(uri)); reqFTP.Method = WebRequestMethods.Ftp.DownloadFile; reqFTP.UseBinary = true; reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword); reqFTP.Proxy = null; System.Text.StringBuilder strMsg; int bufferSize = 2048; byte[] buffer = new byte[bufferSize]; string targetFilePath = DownloadDir + "\\" + fileName; FileStream outputStream = null; FtpWebResponse response = null; Stream ftpStream = null; try { outputStream = new FileStream(targetFilePath, FileMode.Create); response = (FtpWebResponse)reqFTP.GetResponse(); ftpStream = response.GetResponseStream(); long cl = response.ContentLength; int readCount = ftpStream.Read(buffer, 0, bufferSize); while (readCount > 0) { outputStream.Write(buffer, 0, readCount); readCount = ftpStream.Read(buffer, 0, bufferSize); } strMsg = new System.Text.StringBuilder("OK"); } catch (Exception ex) { string ErrStr = ex.ToString(); UtilLog.Error(ex); if (ErrStr.Substring(0, 67).Trim() == "System.Net.WebException: The remote server returned an error: (550)") { strMsg = new System.Text.StringBuilder("Test Program loading error!-程序调用错误!" + "\r\n"); strMsg.Append(fileName + " Program version is not correct!-程序版本号错误!" + "\r\n"); } else { strMsg = new System.Text.StringBuilder("Test Program loading error!-程序调用错误!" + "\r\n"); strMsg.Append(fileName + " Program file doesn't exist!-程序文件不存在!" + "\r\n"); strMsg.Append("Pls try again!-请重新扫描!" + "\r\n"); } if (ftpStream != null) { ftpStream.Close(); } if (outputStream != null) { outputStream.Close(); } if (response != null) { response.Close(); } } finally { if (ftpStream != null) { ftpStream.Close(); } if (outputStream != null) { outputStream.Close(); } if (response != null) { response.Close(); } } return(strMsg.ToString()); }