public FileSystemScan(ModuleBox mBox) { _mBox = new ModuleBox(mBox); _workBodyDi = new List <DirectoryInfo>(); _workBodyFi = new List <FileInfo>(); this.ScanDelegate = UnpackMessage; _mBox.ModListener(new ModuleBox() { CodeId = CodeId.BindwithScan, ScanListener = ScanDelegate }); _mBox.ScanFListener(new ModuleBox() { CodeId = CodeId.BindwithScan, ScanListener = ScanDelegate }); try { foreach (var dirs in _mBox.ApplicationOptions.DirectoriesForScanStart) { _workBodyDi.Add(dirs); } _mBox.ScanFListener(new ModuleBox() { CodeId = CodeId.UpdateLblDirectories, StringBody = _workBodyDi[0].FullName }); } catch (Exception e) { throw new Exception("Init FileSysScan |" + e.Message); } }
public void GetAllDirectoryInfo(object obj) { var mBox = new ModuleBox(obj as ModuleBox); //--------------------------------------------- int lowIndexDirInfo = 0; //lower index list dir_info int lowIndexFileInfo = 0; //lower index list files_info int lowIndexFileScan = 0; //lower index list files_info int thPool = 50; //count task in sys_thread pool int timeout = 100; //timeout for tasks - add to list dir_info string str = ""; //info for scan_form - current directory added to list_info int counEmptyJobDirInfo = 5; //FUSE,breaker int counEmptyJobFileInfo = 5; //FUSE,breaker int counEmptyJobFileScan = 5; //FUSE,breaker bool endGetFolders = false; bool endGetFiles = false; //--------------------------------------------- //--------------------------------------------- while (!_endTasksWithFiles) { lock (_barrier) { if (!_pauseTask && !endGetFolders) { if (lowIndexDirInfo < _workBodyDi.Count) { int count = _workBodyDi.Count - lowIndexDirInfo; if (thPool < count) { count = thPool; } while (count != 0) { ThreadPool.QueueUserWorkItem(AddRangeToListDirInfo, lowIndexDirInfo); count--; lowIndexDirInfo++; } str = $"{lowIndexDirInfo} : " + _workBodyDi[lowIndexDirInfo - 1].FullName; mBox.ScanFListener(new ModuleBox() { CodeId = CodeId.UpdateLblDirectories, StringBody = str }); } else { if (counEmptyJobDirInfo != 0) { counEmptyJobDirInfo--; } else { endGetFolders = true; mBox.ScanFListener(new ModuleBox() { CodeId = CodeId.UpdateLblDirectories, StringBody = @"Завершено." }); } } } if (!_pauseTask && endGetFolders && !endGetFiles) { if (lowIndexFileInfo < _workBodyDi.Count) { int count = _workBodyDi.Count - lowIndexFileInfo; if (thPool < count) { count = thPool; } while (count != 0) { ThreadPool.QueueUserWorkItem(AddRAngeToListFilesInfo, lowIndexFileInfo); count--; lowIndexFileInfo++; } if (lowIndexFileInfo < _workBodyDi.Count) { str = $"{lowIndexFileInfo} : " + _workBodyDi[lowIndexFileInfo].FullName; mBox.ScanFListener( new ModuleBox() { CodeId = CodeId.UpdateLblDirFiles, StringBody = str }); } } else { if (counEmptyJobFileInfo != 0) { counEmptyJobFileInfo--; } else { endGetFiles = true; mBox.ScanFListener(new ModuleBox() { CodeId = CodeId.UpdateLblDirFiles, StringBody = @"Завершено." }); } } } if (!_pauseTask && endGetFolders && endGetFiles) { if (lowIndexFileScan < _workBodyFi.Count) { int i = _workBodyFi.Count - lowIndexFileScan > thPool ? thPool : _workBodyFi.Count - lowIndexFileScan; while (i != 0) { if (_workBodyFi[lowIndexFileScan].Length <= _mBox.ApplicationOptions.FileSizeIgnoreTo && _workBodyFi[lowIndexFileScan].Length >= _mBox.ApplicationOptions.FileSizeIgnoreFrom && _mBox.ApplicationOptions.FileExtensionForExecute.Contains( Path.GetExtension(_workBodyFi[lowIndexFileScan].FullName))) { ThreadPool.QueueUserWorkItem(AuditValid, new ModuleBox(_mBox) { StringBody = _workBodyFi[lowIndexFileScan].FullName }); } i--; lowIndexFileScan++; } mBox.ScanFListener(new ModuleBox() { CodeId = CodeId.ProgresBarMax, IntBody = _workBodyFi.Count }); mBox.ScanFListener(new ModuleBox() { CodeId = CodeId.ProgresBarStep, IntBody = lowIndexFileScan }); } else { if (counEmptyJobFileScan != 0) { counEmptyJobFileScan--; } else { _endTasksWithFiles = true; mBox.ScanFListener(new ModuleBox() { CodeId = CodeId.ProgresBarStep, IntBody = 0 }); Thread.Sleep(5000); mBox.ModListener(new ModuleBox() { CodeId = CodeId.ListReportAudit, StringBody = @"Завершено." }); mBox.ScanFListener(new ModuleBox() { CodeId = CodeId.UpdateLblCurFile, StringBody = @"Завершено." }); } } } } Thread.Sleep(timeout); } }