Пример #1
0
        private void btn_start_Click(object sender, EventArgs e)
        {
            if (FileListView.Items.Count < 1)
            {
                return;
            }

            Program.logger.Info("파일 스캔 시작");

            Task.Factory.StartNew(() =>
            {
                try
                {
                    ChangeEnabled(btn_start, false);

                    Parallel.ForEach(FileListView.Objects.Cast <FileFormat>(), fileFormat =>
                    {
                        Program.logger.Info($"{fileFormat.FileFullPath} 파일 스캔 시작");

                        fileFormat.FileState = VirusTotalState.Working;
                        FileListView.UpdateObject(fileFormat);

                        string fileMD5      = VirusTotal.GetMD5(fileFormat.FileFullPath);
                        fileFormat.FileScan = ApiController.FileReport(fileMD5);

                        if (fileFormat.FileScan is null)
                        {
                            Program.logger.Error($"{fileFormat.FileFullPath} 파일 스캔 에러");
                            fileFormat.FileState = VirusTotalState.Error;
                            FileListView.UpdateObject(fileFormat);
                        }
                        else
                        {
                            if (fileFormat.FileScan.response_code == 0)
                            {
                                //파일 스캔
                                Program.logger.Info($"{fileFormat.FileFullPath} 파일 최초 스캔 필요, 스캔 중");
                                fileFormat.FileScan = ApiController.FileScan(fileFormat.FileFullPath);
                            }

                            if (fileFormat.FileScan.response_code == -2 || (fileFormat.FileScan.response_code == 1 && fileFormat.FileScan.scans is null))
                            {
                                Program.logger.Info($"{fileFormat.FileFullPath} 파일 탐색 리스트 큐 추가, 스캔 중");
                                while (true)
                                {
                                    Thread.Sleep(10000);
                                    fileFormat.FileScan = ApiController.FileReport(fileMD5);

                                    if (fileFormat.FileScan != null)
                                    {
                                        if (fileFormat.FileScan.response_code == 1)
                                        {
                                            ShowBallonTipHandler?.Invoke("스캔 완료", $"{fileFormat.FileName} : 스캔 완료");
                                            break;
                                        }
                                    }
                                    Program.logger.Info($"{fileFormat.FileFullPath} 파일 스캔 중");
                                }
                            }

                            Program.logger.Info($"{fileFormat.FileFullPath} 파일 스캔 완료");
                            fileFormat.FileState = VirusTotalState.Finished;
                            FileListView.UpdateObject(fileFormat);
                        }
                    });
                }
                finally
                {
                    ChangeEnabled(btn_start, true);
                }
            });
        }