Browse Source

Расширение информативности infoLabel.

master
Никита 6 years ago
parent
commit
f18be6efe1
  1. 11
      fileFinder/MainForm.cs
  2. 4
      fileFinder/ProgressReportModel.cs
  3. 30
      fileFinder/TaskController.cs

11
fileFinder/MainForm.cs

@ -78,7 +78,7 @@ namespace fileFinder
switch (mainController.state) switch (mainController.state)
{ {
case TaskState.Work: case TaskState.Work:
updateInfoLabel(report.currentFileUrl, report.progress); updateInfoLabel(report.currentFileUrl, report);
break; break;
case TaskState.Pause: case TaskState.Pause:
updateResultViewer(report.currentTreeNode); 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(); 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); 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; " | Current file: " + fileUrl;
} }
public void updateResultViewer(TreeNode tN) private void updateResultViewer(TreeNode tN)
{ {
if (tN != null) 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 = () => Action refresh = () =>
{ {

4
fileFinder/ProgressReportModel.cs

@ -4,7 +4,9 @@ namespace fileFinder
{ {
class ProgressReportModel 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 string currentFileUrl { get; set; }
public TreeNode currentTreeNode { get; set; } public TreeNode currentTreeNode { get; set; }
} }

30
fileFinder/TaskController.cs

@ -54,10 +54,10 @@ namespace fileFinder
{ {
TaskController controller = this; TaskController controller = this;
TreeNode itemsNode = new TreeNode(); TreeNode itemsNode = new TreeNode();
ProgressReportModel _report = new ProgressReportModel();
List<string> foundFiles = getFileList(query.fileUrl, query.fileNameQuery); List<string> 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) foreach (string item in foundFiles)
{ {
switch (state) switch (state)
@ -65,31 +65,39 @@ namespace fileFinder
case TaskState.Finished: case TaskState.Finished:
return null; return null;
case TaskState.Pause: case TaskState.Pause:
_report.progress = counter; report.Report(createReport((TreeNode)itemsNode.Clone(),
_report.currentFileUrl = item; item, matchingFiles, processedFiles, foundFiles.Count));
_report.currentTreeNode = (TreeNode)itemsNode.Clone();
report.Report(_report);
while (state == TaskState.Pause) while (state == TaskState.Pause)
Thread.Sleep(100); Thread.Sleep(100);
goto case TaskState.Work; goto case TaskState.Work;
case TaskState.Work: case TaskState.Work:
string[] fileLines = getFileContents(item); string[] fileLines = getFileContents(item);
_report.progress = counter; report.Report(createReport(null, item, matchingFiles, processedFiles, foundFiles.Count));
_report.currentFileUrl = item;
report.Report(_report);
if ((fileLines.Length > 0) && (isFileContainQuery(fileLines, query.fileInnerQuery))) if ((fileLines.Length > 0) && (isFileContainQuery(fileLines, query.fileInnerQuery)))
{ {
counter++;
await fillChildNode(itemsNode, item.Replace(query.fileUrl, "")); await fillChildNode(itemsNode, item.Replace(query.fileUrl, ""));
matchingFiles++;
} }
processedFiles++;
break; break;
} }
} }
report.Report(createReport(null, "none", matchingFiles, processedFiles, foundFiles.Count));
controller.stopTask(); controller.stopTask();
return itemsNode; 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<string> getFileList(string directory, string nameQuery) private List<string> getFileList(string directory, string nameQuery)
{ {

Loading…
Cancel
Save