Browse Source

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

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

11
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 = () =>
{

4
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; }
}

32
fileFinder/TaskController.cs

@ -54,42 +54,50 @@ namespace fileFinder
{
TaskController controller = this;
TreeNode itemsNode = new TreeNode();
ProgressReportModel _report = new ProgressReportModel();
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)
{
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<string> getFileList(string directory, string nameQuery)
{

Loading…
Cancel
Save