|
|
@ -1,14 +1,7 @@ |
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.ComponentModel; |
|
|
|
using System.Data; |
|
|
|
using System.Drawing; |
|
|
|
using System.Linq; |
|
|
|
using System.Text; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using System.Windows.Forms; |
|
|
|
using System.IO; |
|
|
|
using System.Threading; |
|
|
|
using System.Timers; |
|
|
|
|
|
|
|
namespace fileFinder |
|
|
@ -19,6 +12,7 @@ namespace fileFinder |
|
|
|
TaskController mainController = new TaskController(); |
|
|
|
SearchQueryModel searchQueryModel; |
|
|
|
System.Timers.Timer updateInfoTimer = new System.Timers.Timer(1000); |
|
|
|
bool isFieldsChanged = false; |
|
|
|
|
|
|
|
public MainForm() |
|
|
|
{ |
|
|
@ -38,7 +32,7 @@ namespace fileFinder |
|
|
|
queryTextBox.Text = sets.fileNameQuery; |
|
|
|
searchQueryModel = mainController.updateSearchQueryModel(sets.fileUrl, |
|
|
|
sets.fileInnerQuery, sets.fileNameQuery); |
|
|
|
mainController.isTaskChanged = false; |
|
|
|
isFieldsChanged = false; |
|
|
|
} |
|
|
|
|
|
|
|
private void fillImagesToResultViewer() |
|
|
@ -81,10 +75,15 @@ namespace fileFinder |
|
|
|
|
|
|
|
private void reportProgress(object sender, ProgressReportModel report) |
|
|
|
{ |
|
|
|
if (!mainController.isPaused) |
|
|
|
updateInfoLabel(report.currentFileUrl, report.progress); |
|
|
|
else if (mainController.isPaused) |
|
|
|
updateResultViewer(report.currentTreeNode); |
|
|
|
switch (mainController.state) |
|
|
|
{ |
|
|
|
case TaskState.Work: |
|
|
|
updateInfoLabel(report.currentFileUrl, report.progress); |
|
|
|
break; |
|
|
|
case TaskState.Pause: |
|
|
|
updateResultViewer(report.currentTreeNode); |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private async void handleSearchBtn_Click(object sender, EventArgs e) |
|
|
@ -92,45 +91,54 @@ namespace fileFinder |
|
|
|
Progress<ProgressReportModel> progress = new Progress<ProgressReportModel>(); |
|
|
|
progress.ProgressChanged += reportProgress; |
|
|
|
|
|
|
|
if (mainController.isStopped || mainController.isTaskChanged) |
|
|
|
if (isFieldsChanged) // если в форме изменился запрос
|
|
|
|
mainController.stopTask(); // то принудительно завершаем задание
|
|
|
|
isFieldsChanged = false; |
|
|
|
|
|
|
|
switch (mainController.state) |
|
|
|
{ |
|
|
|
mainController.stopTask(); |
|
|
|
mainController = new TaskController(); |
|
|
|
searchQueryModel = mainController.updateSearchQueryModel(curDirTextBox.Text, |
|
|
|
queryTextBox.Text, innerQueryTextBox.Text); |
|
|
|
handleSearchBtn.Text = "Pause Task"; |
|
|
|
mainController.beginTask(); |
|
|
|
changeVisibilityResultViewer(); |
|
|
|
TreeNode tN = await Task.Run(() => mainController.buildResultTree(searchQueryModel, progress)); |
|
|
|
if (tN != null) |
|
|
|
{ |
|
|
|
updateResultViewer(tN); |
|
|
|
case TaskState.Created: |
|
|
|
searchQueryModel = mainController.updateSearchQueryModel(curDirTextBox.Text, |
|
|
|
queryTextBox.Text, innerQueryTextBox.Text); |
|
|
|
handleSearchBtn.Text = "Pause Task"; |
|
|
|
mainController.beginTask(); |
|
|
|
changeVisibilityResultViewer(); |
|
|
|
handleSearchBtn.Text = "Start Task"; |
|
|
|
} |
|
|
|
} else if (mainController.isPaused) |
|
|
|
{ |
|
|
|
handleSearchBtn.Text = "Pause Task"; |
|
|
|
mainController.resumeTask(); |
|
|
|
changeVisibilityResultViewer(); |
|
|
|
} else |
|
|
|
{ |
|
|
|
handleSearchBtn.Text = "Resume Task"; |
|
|
|
mainController.pauseTask(); |
|
|
|
changeVisibilityResultViewer(); |
|
|
|
TreeNode tN = await Task.Run(() => mainController.buildResultTree(searchQueryModel, progress)); |
|
|
|
if (tN != null) |
|
|
|
{ |
|
|
|
updateResultViewer(tN); |
|
|
|
handleSearchBtn.Text = "Start Task"; |
|
|
|
} |
|
|
|
break; |
|
|
|
case TaskState.Work: |
|
|
|
handleSearchBtn.Text = "Resume Task"; |
|
|
|
mainController.pauseTask(); |
|
|
|
break; |
|
|
|
case TaskState.Pause: |
|
|
|
handleSearchBtn.Text = "Pause Task"; |
|
|
|
mainController.resumeTask(); |
|
|
|
break; |
|
|
|
case TaskState.Finished: |
|
|
|
mainController = new TaskController(); |
|
|
|
goto case TaskState.Created; |
|
|
|
} |
|
|
|
changeVisibilityResultViewer(); |
|
|
|
} |
|
|
|
|
|
|
|
private void changeVisibilityResultViewer() |
|
|
|
{ |
|
|
|
if (mainController.isStopped || mainController.isPaused) |
|
|
|
{ |
|
|
|
waitOrPauseLabel.Visible = false; |
|
|
|
resultViewer.Enabled = true; |
|
|
|
} else |
|
|
|
switch (mainController.state) |
|
|
|
{ |
|
|
|
waitOrPauseLabel.Visible = true; |
|
|
|
resultViewer.Enabled = false; |
|
|
|
case TaskState.Work: // если задание в работе, то блокируем ResultViewer
|
|
|
|
waitOrPauseLabel.Visible = true; |
|
|
|
resultViewer.Enabled = false; |
|
|
|
break; |
|
|
|
case TaskState.Pause: // если задание на паузе, то показываем промеж. результат
|
|
|
|
waitOrPauseLabel.Visible = false; |
|
|
|
resultViewer.Enabled = true; |
|
|
|
break; |
|
|
|
case TaskState.Finished: // если задание завершено, то показываем результат
|
|
|
|
goto case TaskState.Pause; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -189,9 +197,9 @@ namespace fileFinder |
|
|
|
|
|
|
|
private void changeTaskBtnStatus() |
|
|
|
{ |
|
|
|
if (!mainController.isTaskChanged) |
|
|
|
if (!isFieldsChanged) |
|
|
|
{ |
|
|
|
mainController.isTaskChanged = true; |
|
|
|
isFieldsChanged = true; |
|
|
|
handleSearchBtn.Text = "Start New Task"; |
|
|
|
} |
|
|
|
} |
|
|
|