|
|
@ -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) |
|
|
|
{ |
|
|
|