[15342] | 1 | using System;
|
---|
[15346] | 2 | using System.Collections.Generic;
|
---|
[15342] | 3 | using System.Threading.Tasks;
|
---|
| 4 | using System.Windows.Forms;
|
---|
[15346] | 5 | using HeuristicLab.Clients.Hive;
|
---|
[15342] | 6 | using HeuristicLab.Common;
|
---|
| 7 | using HeuristicLab.Core;
|
---|
| 8 |
|
---|
| 9 | namespace HeuristicLab.HiveDrain {
|
---|
| 10 | public partial class HiveDrainMainWindow : Form {
|
---|
| 11 | public HiveDrainMainWindow() {
|
---|
| 12 | InitializeComponent();
|
---|
| 13 | ContentManager.Initialize(new PersistenceContentManager());
|
---|
[15346] | 14 | ListHiveJobs();
|
---|
[15342] | 15 | }
|
---|
| 16 |
|
---|
[15346] | 17 | private System.Threading.Tasks.Task task;
|
---|
[15342] | 18 |
|
---|
| 19 | public static ThreadSafeLog Log = new ThreadSafeLog();
|
---|
| 20 |
|
---|
| 21 | private void EnableButton() {
|
---|
| 22 | if (InvokeRequired)
|
---|
| 23 | Invoke(new Action(EnableButton));
|
---|
| 24 | else
|
---|
| 25 | downloadButton.Enabled = true;
|
---|
| 26 | }
|
---|
| 27 |
|
---|
| 28 | private void downloadButton_Click(object sender, EventArgs e) {
|
---|
| 29 | string pattern = (patterTextBox.Text.Trim().Length > 0) ? patterTextBox.Text.Trim() : null;
|
---|
| 30 | Log.Clear();
|
---|
| 31 | logView.Content = Log;
|
---|
| 32 | downloadButton.Enabled = false;
|
---|
| 33 |
|
---|
| 34 | JobDownloader jobDownloader = new JobDownloader(Environment.CurrentDirectory, pattern, Log, oneFileCheckBox.Checked);
|
---|
[15346] | 35 | task = new System.Threading.Tasks.Task(jobDownloader.Start);
|
---|
[15342] | 36 | task.ContinueWith(x => { Log.LogMessage("All tasks written, quitting."); EnableButton(); }, TaskContinuationOptions.OnlyOnRanToCompletion);
|
---|
| 37 | task.ContinueWith(x => { Log.LogMessage("Unexpected Exception while draining the Hive: " + x.Exception.ToString()); EnableButton(); }, TaskContinuationOptions.OnlyOnFaulted);
|
---|
| 38 | task.Start();
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 | private void HiveDrainMainWindow_FormClosing(object sender, FormClosingEventArgs e) {
|
---|
| 42 | //TODO: implement task cancelation
|
---|
| 43 | }
|
---|
[15346] | 44 |
|
---|
| 45 | private void ListHiveJobs() {
|
---|
| 46 | if (logView.Content == null)
|
---|
| 47 | logView.Content = Log;
|
---|
| 48 | Log.Clear();
|
---|
| 49 | var jobs = HiveServiceLocator.Instance.CallHiveService<IEnumerable<Job>>(s => s.GetJobs());
|
---|
| 50 | foreach (var job in jobs) {
|
---|
| 51 | Log.LogMessage(string.Format("{0}\t{1}", job.DateCreated, job.Name));
|
---|
| 52 | }
|
---|
| 53 | }
|
---|
[15342] | 54 | }
|
---|
| 55 | }
|
---|