Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.App/JsonInterfaceForm.cs @ 17987

Last change on this file since 17987 was 17828, checked in by dpiringe, 4 years ago

#3026

  • removed the option to set the value for JsonItems via exporter
    • reworked some base controls
    • added new controls for JsonItem specific properties (e.g. ArrayResizable)
    • deleted a lot of obsolet controls
  • removed the Enable checkbox in the detail view of JsonItems
  • exporter now clones the IOptimizer object
  • added a check + message for unsupported exports
  • list of JsonItems now includes unsupported JsonItems (disabled and marked with 'unsupported')
  • refactored the converter type check
    • now every converter has to specify its supported type(s)
File size: 3.6 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Data;
5using System.Drawing;
6using System.Linq;
7using System.Text;
8using System.Threading;
9using System.Threading.Tasks;
10using System.Windows.Forms;
11using HeuristicLab.PluginInfrastructure;
12
13namespace HeuristicLab.JsonInterface.App {
14  public partial class JsonInterfaceForm : Form {
15    private OpenFileDialog openDialog = null;
16    private SaveFileDialog saveDialog = null;
17    private string templatePath = null;
18    private string configPath = null;
19    private string outputPath = null;
20    private int loadingCounter = 0;
21
22    public JsonInterfaceForm() {
23      openDialog = new OpenFileDialog();
24      openDialog.Multiselect = false;
25      openDialog.DefaultExt = ".json";
26      openDialog.AddExtension = true;
27      openDialog.Filter = "Json-File (*.json)|*.json";
28
29      saveDialog = new SaveFileDialog();
30      saveDialog.DefaultExt = ".json";
31      saveDialog.AddExtension = true;
32      saveDialog.Filter = "Json-File (*.json)|*.json";
33
34      InitializeComponent();
35
36      this.templateOpenButton.Image = HeuristicLab.Common.Resources.VSImageLibrary.Open;
37      this.configOpenButton.Image = HeuristicLab.Common.Resources.VSImageLibrary.Open;
38      this.outputOpenButton.Image = HeuristicLab.Common.Resources.VSImageLibrary.Save;
39      this.Icon = HeuristicLab.Common.Resources.HeuristicLab.Icon;
40    }
41
42    private void OpenTemplate(object sender, EventArgs e) {
43      if(openDialog.ShowDialog() == DialogResult.OK) {
44        templatePath = openDialog.FileName;
45        templateTextBox.Text = templatePath;
46      }
47    }
48
49    private void OpenConfig(object sender, EventArgs e) {
50      if (openDialog.ShowDialog() == DialogResult.OK) {
51        configPath = openDialog.FileName;
52        configTextBox.Text = configPath;
53      }
54    }
55
56    private void OpenOutput(object sender, EventArgs e) {
57      if (saveDialog.ShowDialog() == DialogResult.OK) {
58        outputPath = saveDialog.FileName;
59        outputTextBox.Text = outputPath;
60      }
61    }
62
63    /// <summary>
64    /// Run button onClick logic
65    /// </summary>
66    /// <param name="sender"></param>
67    /// <param name="e"></param>
68    private async void Run(object sender, EventArgs e) {
69      runButton.Enabled = false;
70      CancellationTokenSource cts = new CancellationTokenSource();
71      var token = cts.Token;
72
73      // update text on run button to show a working program (loading/working)
74      Task uiUpdater = Task.Run(async () => {
75        while(!token.IsCancellationRequested) {
76
77          StringBuilder sb = new StringBuilder("Run");
78          sb.Append('.', loadingCounter);
79          UpdateButton(sb.ToString());
80          loadingCounter = ++loadingCounter % 3;
81          await Task.Delay(500);
82        }
83      }, token);
84
85      // performs the json interfaces run
86      Task work = Task.Run(() => {
87        if(templatePath != null && configPath != null && outputPath != null) {
88          try {
89            Runner.Run(templatePath, configPath, outputPath);
90          } catch (Exception ex) {
91            ErrorHandling.ShowErrorDialog(this, ex);
92          }
93        }
94        cts.Cancel();
95      });
96
97      await Task.WhenAll(work, uiUpdater);
98
99      runButton.Enabled = true;
100      runButton.Text = "Run";
101    }
102
103    /// <summary>
104    /// Update displayed text for run button.
105    /// </summary>
106    /// <param name="text"></param>
107    private void UpdateButton(string text) {
108      if (InvokeRequired) {
109        Invoke((Action<string>) UpdateButton, text);
110      } else {
111        runButton.Text = text;
112      }
113    }
114  }
115}
Note: See TracBrowser for help on using the repository browser.