FileGenerated.cs 9.9 KB
using log4net;
using OnlineStore.Common;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading;
 

namespace OnlineStore.DeviceLibrary.doubleStore
{
    public class FileGenerated
    {
        public static readonly ILog LOGGER = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

        /**
     * プログラム変更受信     (基板搬入抑制)通知     Program change receive     (board loading prohibit)     notification
     */
        public static string REQUEST_ACK = "ACK";
        /**
         * プログラム変更不可通知     Program change cancel     notification
         */
        public static string REQUEST_CAN = "CAN";
        /**
         * プログラム変更正常終了通知     Program change normal     end notification
         */
        public static string REQUEST_OK = "OK";
        /**
         * プログラム変更異常終了通知     Program change abnormal     end notification
         */
        public static string REQUEST_NG = "NG";
        //private static string remoteURL = ConfigAppSettings.GetValue(Setting_Init.RemoteURL);
        //private static string remoteURL = "//192.168.10.1/othersystem/iLNBIF/MachineIF/M-TowertoiLNB/";
        //private static string remoteURL = "/testFile/";
        private static string remoteURL = ConfigAppSettings.GetValue(Setting_Init.RemoteWriteURL);
        //private static string remoteURL = "//192.168.10.11/doubleStore/";
        private static char spiltStr = '&';
        private static string localFileDir = "F:/FileDir/";

        public static void WriteStrToRemoteUrl(string fileName, string[] lines)
        { 
            try
            {
                if (!Directory.Exists(remoteURL))//若文件夹不存在则新建文件夹   
                {
                    Directory.CreateDirectory(remoteURL); //新建文件夹   
                }
                //先写入本地
                //string localFileFullName = "" + localFileDir + fileName;
                //写入远程共享文件夹
                String FullRemotePath = remoteURL + fileName;
                FileShare.WriteFiles(FullRemotePath, lines);
            }
            catch (Exception ex)
            {
                LogUtil.error(LOGGER,"写入文件出错:[" + fileName + "]"+ex.ToString());
            }
        }
        public static string GetDateStr()
        {
            // MCxxxxx&Lane&YYYYMMDDhhmmss&ZZ&TTTT&BZ&LV&A-A.SGI 
            string dateStr = DateTime.Now.ToString("yyyyMMddHHmmss");
            return dateStr;
        }

        /**
         * 8.2.1.1. ファイル名/File name  MCxxxxx&Lane&YYYYMMDDhhmmss&ZZ&TTTT&BZ&LV&A-A.SGI
         * 設備起動時。状態が変わった時     When machine started     When state changed
         */
        public static void writeSGIFile(string machineId, string lightT, string alarmInfo, string errorInfo, int autoRun, int troubleStop)
        {
            string fileEndName = ".SGI";

            //固定值レーン No. 01 固定
            string BZ = "0";
            string ZZ = "00";
            string lane = "01";

            //拼接长度
            lightT = lightT.PadLeft(4, '0');
            machineId = machineId.PadLeft(5, '0');
            alarmInfo = alarmInfo.PadLeft(2, '0');
            errorInfo = errorInfo.PadLeft(8, '0');

            string fileName = "MC" + machineId + spiltStr + lane + spiltStr + GetDateStr() + spiltStr + ZZ +
                    spiltStr + lightT + spiltStr + BZ + spiltStr + alarmInfo + spiltStr + errorInfo + fileEndName;
            String warnMessage = DBStoreManager.GetWarMsg();
            FileInfomation fileInfo = new FileInfomation();
            string[] text = fileInfo.WarnMsgToFileString(warnMessage);
            //FileInfomation fileInfo = new FileInfomation(autoRun, troubleStop);
            //string[] text = fileInfo.ToFileString();
            WriteStrToRemoteUrl(fileName, text);
        }

        /**
         * 8.2.2.1. ファイル名/File name  MCxxxxx&Lane&YYYYMMDDhhmmss &ZZ.STS
         * 設備起動時。状態が変わった時     When machine started     When state changed
         */
        public static void writeSTSFile(string machineId, int autoRun, int troubleStop)
        {
            string fileEndName = ".STS";

            //固定值レーン No. 01 固定
            string ZZ = "00";
            string lane = "01";

            //拼接长度
            machineId = machineId.PadLeft(5, '0');

            string fileName = "MC" + machineId + spiltStr + lane + spiltStr + GetDateStr() + spiltStr + ZZ + fileEndName;

            FileInfomation fileInfo = new FileInfomation(autoRun, troubleStop);
            string[] text = fileInfo.ToFileString();
            //string[] text = new string[] { };
            WriteStrToRemoteUrl(fileName, text);
        }

        /**
         * 8.2.3.1. ファイル名/File name (△2)  MCxxxxx&Lane&CC.LCT
         * 設備状態を常時出力( 500ms~可 変) Always output machine state     (500ms–variable)
         * 一直需要输出的文件
         */
        public static void writeLCTFile(string machineId, int autoRun, int troubleStop,int pcbCount)
        {
            string fileEndName = ".LCT";

            string CC =pcbCount.ToString().PadLeft(2,'0') ;
            string lane = "01";
            //拼接长度
            machineId = machineId.PadLeft(5, '0');
            string fileName = "MC" + machineId + spiltStr + lane + spiltStr + CC + fileEndName;

            //FileInfomation fileInfo = new FileInfomation(autoRun, troubleStop);
            //string[] text = fileInfo.ToFileString();
            string[] text = new string[] { };
            WriteStrToRemoteUrl(fileName, text);
        }


        /**
         * 8.2.3.1. ファイル名/File name (△2)  MCxxxxx&Lane.LST
         * 設備状態を常時出力( 500ms~可 変) Always output machine state     (500ms–variable)
         * 一直需要输出的文件
         */
        public static void writeLSTFile(string machineId)
        {
            string fileEndName = ".LST";
            
            string lane = "01";
            //拼接长度
            machineId = machineId.PadLeft(5, '0');
            string fileName = "MC" + machineId + spiltStr + lane + fileEndName;

            //FileInfomation fileInfo = new FileInfomation(autoRun, troubleStop);
            //string[] text = fileInfo.ToFileString();
             
            string[] text = new string[] {
                "PROGRAM_NAME1",
                "PROGRAM_NAME2",
                "PROGRAM_NAME3"
            };
            text = DBLineControl.GetProgramList();
            WriteStrToRemoteUrl(fileName, text);
        }


        /**
         * 10.1.2. 機種切り替え替えに使用するファイル一覧/List of files used for product change
         * プログラム変更受信 (基板搬入抑制)通知 Program change receive (board loading prohibit) notification
         * MCxxxxx&Lane&A-A&P-P&YYYYMMDDhhmmss.ACK
         */
        public static void writeACKFile(string machineId, string AA, string PP,string m_time)
        {
            string fileEndName = ".ACK";
            
            string lane = "01";

            string fileName = "MC" + machineId + spiltStr + lane + spiltStr + AA + spiltStr + PP + spiltStr + m_time + fileEndName;
            
            string[] text = new string[] { };
            WriteStrToRemoteUrl(fileName, text);
        }


        /**
         * 10.1.2. 機種切り替え替えに使用するファイル一覧/List of files used for product change
         * Program change notification
         * MCxxxxx&Lane&A-A&P-P&YYYYMMDDhhmmss.RequestType
         */
        public static void writeRequestFile(string machineId, string AA, string PP, string RequestType,string m_time)
        {
            string fileEndName = "." + RequestType;
            string lane = "01";
            //拼接长度
            machineId = machineId.PadLeft(5, '0');
            //AA = AA.PadLeft(10, '0');
            string fileName = "MC" + machineId + spiltStr + lane + spiltStr + AA + spiltStr + PP + spiltStr + m_time + fileEndName;
            string[] text = new string[] { };
            WriteStrToRemoteUrl(fileName, text);
        } 
        /**
         * 10.1.2. 機種切り替え替えに使用するファイル一覧/List of files used for product change
         * MCxxxxx&Lane&A-A&P-P&YYYYMMDDhhmmss.CMD
         * 由iLNB方创建
         */
        public static void ReadCMDFile(string fullPath,String fileNameh)
        {
            String fileName = System.IO.Path.GetFileName(fileNameh);
            String[] txt = fileName.Split(spiltStr);
            String machineId = txt[0].Replace("MC","");
            String AA = txt[2];
            String PP = txt[3];
            String m_time = txt[4].Substring(0,14);
            writeACKFile(machineId, AA, PP, m_time);
            DBLineControl.UpdateProject(AA,PP,m_time);
            //String RequestType = "OK";
            //writeRequestFile(machineId, AA, PP, RequestType, m_time);
            //删除文件
            //string fullPath = "//192.168.10.1/othersystem/iLNBIF/MachineIF/iLNBtoM-Tower/" + fileNameh;
            Thread.Sleep(100);
            deleteFile(fullPath);
        }

        /**
         * 启动文件夹监视
         */
         public static void StartListerDirectory(String DirectoryPath,String filter)
        {
            FileLister.WatcherStrat(DirectoryPath, filter);
        }

        public static void deleteFile(String fullName)
        {
            try
            {
                //if (!Directory.Exists(remoteURL))//若文件夹不存在则新建文件夹   
                //{
                    
                //}
                File.Delete(fullName); //新建文件夹   
            }
            catch (Exception ex)
            {
                LogUtil.error(LOGGER,"写入文件出错:[" + fullName + "]"+ex.ToString());
            }
        }
    }
}