Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/FileManager.cs @ 17453

Last change on this file since 17453 was 17436, checked in by dpiringe, 5 years ago

#3026:

  • removed unnecessary code in FileManager
  • updated ExportJsonDialog and Testprogram (Heuristiclab.ConfigStarter/Program.cs) to use the new GenerateTemplate method
File size: 2.2 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.IO;
4using System.Linq;
5using System.Text;
6using System.Threading.Tasks;
7using System.Windows.Forms;
8using HeuristicLab.Common;
9using HeuristicLab.Core;
10using HeuristicLab.MainForm;
11using HeuristicLab.Optimization;
12using HeuristicLab.PluginInfrastructure;
13
14namespace HeuristicLab.JsonInterface.OptimizerIntegration {
15  internal static class FileManager {
16    private static OpenFileDialog openFileDialog;
17    private static ExportJsonDialog exportDialog = new ExportJsonDialog();
18
19    public static void ExportJsonTemplate() {
20      IContentView activeView = MainFormManager.MainForm.ActiveView as IContentView;
21      if (activeView != null) {
22        ExportJsonTemplate(activeView);
23      }
24    }
25    public static void ExportJsonTemplate(IContentView view) {
26      // TODO: view to select free params, warning if no results are generated
27      IStorableContent content = view.Content as IStorableContent;
28      if (!view.Locked && content != null) {
29        exportDialog.Content = content;
30        exportDialog.ShowDialog();
31      }
32    }
33
34
35    public static void ImportJsonTemplate() {
36      if (openFileDialog == null) {
37        openFileDialog = new OpenFileDialog();
38        openFileDialog.Title = "Import .json-Template";
39        openFileDialog.FileName = "Item";
40        openFileDialog.Multiselect = false;
41        openFileDialog.DefaultExt = "json";
42        openFileDialog.Filter = ".json-Template|*.json|All Files|*.*";
43      }
44
45      if (openFileDialog.ShowDialog() == DialogResult.OK) {
46        try {
47          var content = JsonTemplateInstantiator.Instantiate(openFileDialog.FileName);
48          IView view = MainFormManager.MainForm.ShowContent(content);
49          if (view == null)
50            ErrorHandling.ShowErrorDialog("There is no view for the loaded item. It cannot be displayed.", new InvalidOperationException("No View Available"));
51        } catch (Exception ex) {
52          ErrorHandling.ShowErrorDialog((Control)MainFormManager.MainForm, "Cannot open file.", ex);
53        } finally {
54          ((MainForm.WindowsForms.MainForm)MainFormManager.MainForm).ResetAppStartingCursor();
55        }
56      }
57    }
58  }
59}
Note: See TracBrowser for help on using the repository browser.