Free cookie consent management tool by TermsFeed Policy Generator

source: misc/tools/HeuristicLab.HiveDrain/HeuristicLab.HiveDrain/HiveDrainMainWindow.cs @ 15681

Last change on this file since 15681 was 15494, checked in by bburlacu, 6 years ago

#2829: Add option to select the save path for the downloaded jobs. Automatically remove duplicate datasets when the job is saved in a single file. Add button to manually list hive jobs.

File size: 2.6 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      var directory = outputDirectoryTextBox.Text;
35
36      if (string.IsNullOrEmpty(directory))
37        directory = Environment.CurrentDirectory;
38
39      JobDownloader jobDownloader = new JobDownloader(directory, pattern, Log, oneFileCheckBox.Checked);
40      task = new System.Threading.Tasks.Task(jobDownloader.Start);
41      task.ContinueWith(x => { Log.LogMessage("All tasks written, quitting."); EnableButton(); }, TaskContinuationOptions.OnlyOnRanToCompletion);
42      task.ContinueWith(x => { Log.LogMessage("Unexpected Exception while draining the Hive: " + x.Exception.ToString()); EnableButton(); }, TaskContinuationOptions.OnlyOnFaulted);
43      task.Start();
44    }
45
46    private void HiveDrainMainWindow_FormClosing(object sender, FormClosingEventArgs e) {
47      //TODO: implement task cancelation
48    }
49
50    private void ListHiveJobs() {
51      if (logView.Content == null)
52        logView.Content = Log;
53      Log.Clear();
54      var jobs = HiveServiceLocator.Instance.CallHiveService<IEnumerable<Job>>(s => s.GetJobs());
55      foreach (var job in jobs) {
56        Log.LogMessage(string.Format("{0}\t{1}", job.DateCreated, job.Name));
57      }
58    }
59
60    private void browseOutputPathButton_Click(object sender, EventArgs e) {
61      var path = string.Empty;
62
63      var dialog = new FolderBrowserDialog {
64        RootFolder = Environment.SpecialFolder.MyComputer
65      };
66
67      if (dialog.ShowDialog() == DialogResult.OK) {
68        path = dialog.SelectedPath;
69      }
70
71      if (!string.IsNullOrEmpty(path))
72        outputDirectoryTextBox.Text = path;
73    }
74
75    private void listJobsButton_Click(object sender, EventArgs e) {
76      ListHiveJobs();
77    }
78  }
79}
Note: See TracBrowser for help on using the repository browser.