From f18be6efe1a69487220d24b22135d5fe7051bb64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=B8=D1=82=D0=B0?= Date: Thu, 4 Oct 2018 02:03:34 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B0=D1=81=D1=88=D0=B8=D1=80=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=B8=D0=BD=D1=84=D0=BE=D1=80=D0=BC=D0=B0?= =?UTF-8?q?=D1=82=D0=B8=D0=B2=D0=BD=D0=BE=D1=81=D1=82=D0=B8=20infoLabel.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fileFinder/MainForm.cs | 11 ++++++----- fileFinder/ProgressReportModel.cs | 4 +++- fileFinder/TaskController.cs | 32 +++++++++++++++++++------------ 3 files changed, 29 insertions(+), 18 deletions(-) diff --git a/fileFinder/MainForm.cs b/fileFinder/MainForm.cs index a0fa060..e637fb1 100644 --- a/fileFinder/MainForm.cs +++ b/fileFinder/MainForm.cs @@ -78,7 +78,7 @@ namespace fileFinder switch (mainController.state) { case TaskState.Work: - updateInfoLabel(report.currentFileUrl, report.progress); + updateInfoLabel(report.currentFileUrl, report); break; case TaskState.Pause: updateResultViewer(report.currentTreeNode); @@ -142,16 +142,17 @@ namespace fileFinder } } - public void updateInfoLabel (string fileUrl, int counter) + private void updateInfoLabel(string fileUrl, ProgressReportModel rpm) { TimeSpan tS = mainController.elapsedTime(); + string fileNumCounters = rpm.matchingFiles + "/" + rpm.processedFiles + "/" + rpm.totalNumOfFiles; string time = String.Format("{0:00}:{1:00}:{2:00}", tS.Hours, tS.Minutes, tS.Seconds); - infoLabel.Text = "Time: " + time + " " + "| Processed files: " + counter + + infoLabel.Text = "Time: " + time + " " + "| Processed files: " + fileNumCounters + " | Current file: " + fileUrl; } - public void updateResultViewer(TreeNode tN) + private void updateResultViewer(TreeNode tN) { if (tN != null) { @@ -160,7 +161,7 @@ namespace fileFinder } } - public void refreshInfoByTimer (object sender, ElapsedEventArgs e) + private void refreshInfoByTimer (object sender, ElapsedEventArgs e) { Action refresh = () => { diff --git a/fileFinder/ProgressReportModel.cs b/fileFinder/ProgressReportModel.cs index b459a40..a36cbfa 100644 --- a/fileFinder/ProgressReportModel.cs +++ b/fileFinder/ProgressReportModel.cs @@ -4,7 +4,9 @@ namespace fileFinder { class ProgressReportModel { - public int progress { get; set; } + public int matchingFiles { get; set; } + public int processedFiles { get; set; } + public int totalNumOfFiles { get; set; } public string currentFileUrl { get; set; } public TreeNode currentTreeNode { get; set; } } diff --git a/fileFinder/TaskController.cs b/fileFinder/TaskController.cs index 22988ec..c362e54 100644 --- a/fileFinder/TaskController.cs +++ b/fileFinder/TaskController.cs @@ -54,42 +54,50 @@ namespace fileFinder { TaskController controller = this; TreeNode itemsNode = new TreeNode(); - ProgressReportModel _report = new ProgressReportModel(); List foundFiles = getFileList(query.fileUrl, query.fileNameQuery); + report.Report(createReport(null, null, 0, 0, foundFiles.Count)); - int counter = 0; + int matchingFiles = 0, processedFiles = 0; foreach (string item in foundFiles) { switch (state) { case TaskState.Finished: return null; - case TaskState.Pause: - _report.progress = counter; - _report.currentFileUrl = item; - _report.currentTreeNode = (TreeNode)itemsNode.Clone(); - report.Report(_report); + case TaskState.Pause: + report.Report(createReport((TreeNode)itemsNode.Clone(), + item, matchingFiles, processedFiles, foundFiles.Count)); while (state == TaskState.Pause) Thread.Sleep(100); goto case TaskState.Work; case TaskState.Work: string[] fileLines = getFileContents(item); - _report.progress = counter; - _report.currentFileUrl = item; - report.Report(_report); - + report.Report(createReport(null, item, matchingFiles, processedFiles, foundFiles.Count)); if ((fileLines.Length > 0) && (isFileContainQuery(fileLines, query.fileInnerQuery))) { - counter++; await fillChildNode(itemsNode, item.Replace(query.fileUrl, "")); + matchingFiles++; } + processedFiles++; break; } } + report.Report(createReport(null, "none", matchingFiles, processedFiles, foundFiles.Count)); controller.stopTask(); return itemsNode; } + private ProgressReportModel createReport(TreeNode treeNode, string fileUrl, int matchingFiles, int processedFiles, int totalNumOfFiles) + { + ProgressReportModel prm = new ProgressReportModel(); + prm.currentTreeNode = treeNode; + prm.currentFileUrl = fileUrl; + prm.matchingFiles = matchingFiles; + prm.processedFiles = processedFiles; + prm.totalNumOfFiles = totalNumOfFiles; + return prm; + } + private List getFileList(string directory, string nameQuery) {