Exemplo n.º 1
0
        private void parsedataservice()
        {
            string strPathdata = Util.PathDataParsingService;
            strPathdata = @"c:\temp";

            string strPathdup = strPathdata + @"\duplicate";
            string strPatharchive = strPathdata + @"\archive";
            string strPathfailure = strPathdata + @"\failure";


            //FileInfo[] FI = _Util.GetFileInfoArray(stPathdata, "std");
            FileInfo[] FI = getFileInfo(strPathdata);

            //DataTable tblData = new DataTable();
            DataTable[] tblPasingService = new DataTable[6];
            DataTable tblPass = new DataTable();
            DataTable tblSession = new DataTable();
            DataTable tblCpk1 = new DataTable();

            DataParse _dp = new DataParse();

            try
            {

                if (!EventLog.SourceExists(sSource)) EventLog.CreateEventSource(sSource, sLog);

                foreach (FileInfo tmpFI in FI)
                {
                    sEvent = "Parsing start; " + DateTime.Now.Millisecond + "ms; " + tmpFI.Name;
                    EventLog.WriteEntry(sSource, sEvent, EventLogEntryType.Information);

                    File.SetAttributes(tmpFI.FullName, FileAttributes.Normal);

                    if (tmpFI.Extension == "std" || tmpFI.Extension == "stdf")
                    {
                        #region parsing std file
                        tblPasingService[0] = _dp.GetDataFromStdfviewer(tmpFI.FullName);
                        
                        tblPass = delFailureData(tblPasingService[0]);

                        if (tblPass.Rows.Count < 5)
                        {
                            if (!Directory.Exists(strPathfailure)) Directory.CreateDirectory(strPathfailure);
                            File.Move(tmpFI.FullName, strPathfailure + "\\" + tmpFI.Name);
                            sEvent = "No enough pass device data, skip parsing " + tmpFI.Name;
                            EventLog.WriteEntry(sSource, sEvent, EventLogEntryType.Warning);
                            continue;
                        }

                        tblSession = getSessionInfo(_dp);
                        tblCpk1 = _Analysis.CaculateCpk(tblPass, _dp.FreezeColumn);

                        sEvent = "Parsing finish; " + DateTime.Now.Millisecond + "ms; " + tmpFI.Name;
                        EventLog.WriteEntry(sSource, sEvent, EventLogEntryType.Information);

                        insert2database(tblSession, tblCpk1);

                        sEvent = "Data added to database; " + DateTime.Now.Millisecond + "ms; " + tmpFI.Name;
                        EventLog.WriteEntry(sSource, sEvent, EventLogEntryType.Information);
                        
                        #endregion parsing std file
                    }
                    else if (tmpFI.Extension == "csv")
                    {
                        #region parsing csv file
                        tblPasingService = _dp.GetDataFromAceTechCsv(tmpFI.FullName);

                        sEvent = "Parsing finish; " + DateTime.Now.Millisecond + "ms; " + tmpFI.Name;
                        EventLog.WriteEntry(sSource, sEvent, EventLogEntryType.Information);

                        for (int i = 0; i < 6; i++)
                        {
                            if (tblPasingService[i].Rows.Count < 5) continue;

                            tblPass = delFailureData(tblPasingService[i]);

                            tblSession = getSessionInfo(_dp);
                            tblCpk1 = _Analysis.CaculateCpk(tblPass, _dp.FreezeColumn);

                            insert2database(tblSession, tblCpk1);
                        }
                        sEvent = "Data added to database; " + DateTime.Now.Millisecond + "ms; " + tmpFI.Name;
                        EventLog.WriteEntry(sSource, sEvent, EventLogEntryType.Information);

                        #endregion parsing csv file
                    }


                    if (!File.Exists(strPatharchive + "\\" + tmpFI.Name))
                    {
                        if (!Directory.Exists(strPatharchive)) Directory.CreateDirectory(strPatharchive);
                        File.Move(tmpFI.FullName, strPatharchive + "\\" + tmpFI.Name);
                        //File.Delete(tmpFI.FullName);
                    }
                    else
                    {
                        if (!Directory.Exists(strPathdup)) Directory.CreateDirectory(strPathdup);
                        File.Move(tmpFI.FullName, strPathdup + "\\" + tmpFI.Name);


                        sEvent = "Duplicate file exist in archive folder, move to duplicate folder instead; " + DateTime.Now.Millisecond + "ms; " + tmpFI.Name;
                        EventLog.WriteEntry(sSource, sEvent, EventLogEntryType.Warning);
                    }
                
                }
            }
            catch (Exception ex)
            {
                sEvent = ex.Message + ";" + ex.HelpLink + ";" + ex.Source;
                EventLog.WriteEntry(sSource, sEvent, EventLogEntryType.Error);
                throw new Exception(ex.Message.ToString());
            }

        }
Exemplo n.º 2
0
        /// <summary>
        /// // Paring data based on different file extension 
        /// </summary>
        /// <param name="strFileName"></param>
        /// <returns>Datatable[0] --> Header, Datatable[1] --> Data</returns>
        private async Task<DataTable[]> FetchDataTask(string[] strFileName)
        {
            #region *** Parsing data ***
            DataParse _DP = new DataParse();
            DataTable[] tblResult = new DataTable[2];
            DataTable tblHeadResult = new DataTable();
            DataTable tblDataResult = new DataTable();
            string strExtension = Path.GetExtension(strFileName[0]);

            if (strExtension.ToLower() == ".txt")
            {
                if (strFileName.Length == 1)
                    tblDataResult = _DP.GetDataFromTxt(strFileName[0]);
                else if (strFileName.Length > 1)
                    tblDataResult = _DP.GetDataFromTxt(strFileName);
            }
            else if (strExtension.ToLower() == ".std" || strExtension.ToLower() == ".stdf")
            {
                if (strFileName.Length == 1)
                {
                    using (FileStream fs = new FileStream(strFileName[0], FileMode.Open))
                    {
                        tblDataResult = await Task.Run(() => _DP.GetDataFromStdfviewer(fs));
                    }
                }
                else if (strFileName.Length > 1)
                {
                    tblDataResult = await Task.Run(() => _DP.GetDataFromStdfviewerTask(strFileName));
                }
            }
            else if (strExtension.ToLower() == ".gz")
            {
                if (strFileName.Length == 1)
                {
                    using (FileStream fs = new FileStream(strFileName[0], FileMode.Open))
                    {
                        using (GZipStream gzs = new GZipStream(fs, CompressionMode.Decompress))
                        {
                            tblDataResult = await Task.Run(() => _DP.GetDataFromStdfviewer(gzs));
                        }
                    }
                }
                else
                {
                    tblDataResult = await Task.Run(() => _DP.GetDataFromStdfviewerTask(strFileName));
                }
            }

            #endregion *** Parsing data ***

            intFrozenColumn = _DP.FreezeColumn;
            _DataParse = _DP;

            #region *** Caculate Header ***

            //int strNameLength = 20;
            bool isHeadNull = false;
            var type = typeof(DataHeader);
            var fields = type.GetFields();

            tblHeadResult.Columns.Add("Name", typeof(string));
            tblHeadResult.Columns.Add("Value", typeof(string));

            //Array.ForEach(fields, f =>
            foreach (_FieldInfo fi in fields)
            {
                string name = fi.Name;
                DataRow dr = tblHeadResult.NewRow();
                dr["Name"] = fi.Name;
                //check if header null
                if (name == "Product")
                {
                    if (fi.GetValue(_DP.Header) == null)
                    {
                        isHeadNull = true;
                    }
                }
                //if header null, use Test quantity to caculate yield
                if (isHeadNull)
                {
                    if (name == "TestQuantity")
                    {
                        dr["Value"] = _DP.TestedDevice;
                    }
                    else if (name == "PassQuantity")
                    {
                        dr["Value"] = _DP.PassedDevice;
                    }
                    else if (name == "FailQuantity")
                    {
                        dr["Value"] = _DP.FailedDevice;
                    }
                    else if (name == "Yield")
                    {
                        double pass = Convert.ToDouble(_DP.PassedDevice);
                        double total = Convert.ToDouble(_DP.TestedDevice);
                        dr["Value"] = Math.Round(pass / total * 100, 3) + "%";
                    }
                }
                //if header not null, use header info
                else
                {
                    if (name == "Yield")
                    {
                        dr["Value"] = fi.GetValue(_DP.Header) + "%";
                    }
                    else
                    {
                        dr["Value"] = fi.GetValue(_DP.Header);
                    }
                }
                tblHeadResult.Rows.Add(dr);
            }
            #endregion *** Caculate Header ***

            tblResult[0] = tblHeadResult;
            tblResult[1] = tblDataResult;
            return tblResult;
        }