Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 18043 was 18043, checked in by dpiringe, 3 years ago

#3026

  • code cleanup
File size: 2.2 KB
Line 
1using System;
2using System.Windows.Forms;
3using HeuristicLab.Common;
4using HeuristicLab.MainForm;
5using HeuristicLab.Optimization;
6using HeuristicLab.PluginInfrastructure;
7
8namespace HeuristicLab.JsonInterface.OptimizerIntegration {
9  internal static class FileManager {
10    private static OpenFileDialog openFileDialog;
11    private static ExportJsonDialog exportDialog = new ExportJsonDialog();
12
13    public static void ExportJsonTemplate() {
14      IContentView activeView = MainFormManager.MainForm.ActiveView as IContentView;
15      if (activeView != null) {
16        ExportJsonTemplate(activeView);
17      }
18    }
19    public static void ExportJsonTemplate(IContentView view) {
20      IStorableContent content = view.Content as IStorableContent;
21      if (!view.Locked && content != null) {
22        if(content is IOptimizer) {
23          exportDialog.Content = content;
24          exportDialog.ShowDialog();
25        } else {
26          MessageBox.Show("This cannot item cannot be converted.", "Unsupported Item", MessageBoxButtons.OK);
27        }
28      }
29    }
30
31
32    public static void ImportJsonTemplate() {
33      if (openFileDialog == null) {
34        openFileDialog = new OpenFileDialog();
35        openFileDialog.Title = "Import .json-Template";
36        openFileDialog.FileName = "Item";
37        openFileDialog.Multiselect = false;
38        openFileDialog.DefaultExt = "json";
39        openFileDialog.Filter = ".json-Template|*.json|All Files|*.*";
40      }
41
42      if (openFileDialog.ShowDialog() == DialogResult.OK) {
43        try {
44          var content = JsonTemplateInstantiator.Instantiate(openFileDialog.FileName);
45          IView view = MainFormManager.MainForm.ShowContent(content.Optimizer);
46          if (view == null)
47            ErrorHandling.ShowErrorDialog("There is no view for the loaded item. It cannot be displayed.", new InvalidOperationException("No View Available"));
48        } catch (Exception ex) {
49          ErrorHandling.ShowErrorDialog((Control)MainFormManager.MainForm, "Cannot open file.", ex);
50        } finally {
51          ((MainForm.WindowsForms.MainForm)MainFormManager.MainForm).ResetAppStartingCursor();
52        }
53      }
54    }
55  }
56}
Note: See TracBrowser for help on using the repository browser.