Esempio n. 1
0
        /// <summary>
        /// 파일 다운로드
        /// </summary>
        private void FileDownload()
        {
            try
            {
                DoEvent(false, "Chack Download File...");

                pAutoDownloadEntity.FILE_TYPE = strFileType;

                using (DataTable dt = new AutoDownloadBusiness().FileInfo_GetList(pAutoDownloadEntity))
                {
                    int intUpdateTotalCount = dt.Rows.Count;
                    int intUpdateCount      = 0;

                    DoEvent(false, string.Format("Update File List {0} Files - Start File Download...", intUpdateTotalCount.ToString()));

                    foreach (DataRow dr in dt.Rows)
                    {
                        intUpdateCount++;

                        CoFAS_ControlManager.InvokeIfNeeded(_lbFileCount, () => _lbFileCount.Text = string.Format("{0:D0}%  {1:D2}/{2:D2}", 100 * intUpdateCount / intUpdateTotalCount, intUpdateCount, intUpdateTotalCount));

                        CoFAS_ControlManager.InvokeIfNeeded(_pgrAutodownloadAll, () => {
                            _pgrAutodownloadAll.Properties.Maximum = intUpdateTotalCount;
                            _pgrAutodownloadAll.Properties.Minimum = 0;
                            _pgrAutodownloadAll.PerformStep();
                            _pgrAutodownloadAll.Update();
                        });

                        string   strFileName     = strTargetPath + @"\" + CoFAS_ConvertManager.obj2String(dr["FILENAME"]);
                        string   strTempFileName = strPathUpdate + CoFAS_ConvertManager.obj2String(dr["FILENAME"]);
                        string   strVersion      = CoFAS_ConvertManager.obj2String(dr["VERSION"]);
                        DateTime dtFileDate      = (DateTime)dr["FILE_DATE"];
                        string   strCrc          = CoFAS_ConvertManager.obj2String(dr["CRC"]);
                        int      intFileSize     = Convert.ToInt32(dr["FILE_SIZE"]);
                        bool     isUpdate        = false;

                        string   strFileVersion = string.Empty;
                        DateTime dtFileFileDate = DateTime.Now;

                        isUpdate = false;

                        DoEvent(false, string.Format("Check the file '{0}'", dr["FILENAME"]));

                        if (CoFAS_FileManager.FileExists(strFileName))
                        {
                            System.IO.FileInfo fi = new System.IO.FileInfo(strFileName);

                            strFileVersion = CoFAS_ConvertManager.obj2String(CoFAS_FileManager.FileGetVersion(fi.FullName));
                            dtFileFileDate = fi.LastWriteTime;

                            if (strFileVersion != strVersion || CoFAS_ConvertManager.obj2String(dtFileFileDate) != CoFAS_ConvertManager.obj2String(dtFileDate))
                            {
                                isUpdate = true;
                            }
                        }
                        else
                        {
                            isUpdate = true;
                        }

                        int intErrCnt = 0;
                        while (isUpdate)
                        {
                            pAutoDownloadEntity.FILE_TYPE = "MES";
                            pAutoDownloadEntity.FILENAME  = CoFAS_ConvertManager.obj2String(dr["FILENAME"]);
                            pAutoDownloadEntity.FILE_PATH = strPathUpdate;

                            string strFileCrc = new AutoDownloadBusiness().FileInfo_GetFileData(pAutoDownloadEntity);

                            GC.Collect();
                            Application.DoEvents();
                            GC.WaitForPendingFinalizers();

                            //crc검사
                            if (strCrc != strFileCrc)
                            {
                                intErrCnt++;

                                CoFAS_FileManager.FileDelete(strPathUpdate + CoFAS_ConvertManager.obj2String(dr["FILENAME"]));

                                //3회까지 시도한다.
                                if (intErrCnt > 2)
                                {
                                    isUpdate = false;
                                }
                                else
                                {
                                    isUpdate = true;
                                }
                            }
                            else
                            {
                                isUpdate = false;
                                System.IO.FileInfo fi = new System.IO.FileInfo(strTempFileName);
                                fi.LastWriteTime = dtFileDate;
                            }
                        }
                    }
                }

                DoEvent(false, string.Format("Completed downloading files from server"));
            }
            catch
            {
                throw;
            }
            finally
            {
            }
        }