Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/tools/HeuristicLab.HiveDrain/HeuristicLab.HiveDrain/HiveDrainMainWindow.cs @ 15346

Last change on this file since 15346 was 15346, checked in by bburlacu, 7 years ago

#2829: List hive jobs when the window is opened.

File size: 2.0 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Threading.Tasks;
4using System.Windows.Forms;
5using HeuristicLab.Clients.Hive;
6using HeuristicLab.Common;
7using HeuristicLab.Core;
8
9namespace HeuristicLab.HiveDrain {
10  public partial class HiveDrainMainWindow : Form {
11    public HiveDrainMainWindow() {
12      InitializeComponent();
13      ContentManager.Initialize(new PersistenceContentManager());
14      ListHiveJobs();
15    }
16
17    private System.Threading.Tasks.Task task;
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);
35      task = new System.Threading.Tasks.Task(jobDownloader.Start);
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    }
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    }
54  }
55}
Note: See TracBrowser for help on using the repository browser.