Free cookie consent management tool by TermsFeed Policy Generator

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

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

#3026

  • adjusted the necessary plugin dependencies for all three JsonInterface projects (depending on CheckPluginDependenciesForReferencedAssemblies and CheckReferenceAssembliesForPluginDependencies tests)
  • using now the error handling dialog in FileManager
  • added a AggregateException in RegressionProblemDataConverter for unconvertable values
File size: 2.3 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          try {
24            exportDialog.Content = content;
25            exportDialog.ShowDialog();
26          } catch (Exception e) {
27            ErrorHandling.ShowErrorDialog(e);
28          }
29        } else {
30          MessageBox.Show("This cannot item cannot be converted.", "Unsupported Item", MessageBoxButtons.OK);
31        }
32      }
33    }
34
35
36    public static void ImportJsonTemplate() {
37      if (openFileDialog == null) {
38        openFileDialog = new OpenFileDialog();
39        openFileDialog.Title = "Import .json-Template";
40        openFileDialog.FileName = "Item";
41        openFileDialog.Multiselect = false;
42        openFileDialog.DefaultExt = "json";
43        openFileDialog.Filter = ".json-Template|*.json|All Files|*.*";
44      }
45
46      if (openFileDialog.ShowDialog() == DialogResult.OK) {
47        try {
48          var content = JsonTemplateInstantiator.Instantiate(openFileDialog.FileName);
49          IView view = MainFormManager.MainForm.ShowContent(content.Optimizer);
50          if (view == null)
51            ErrorHandling.ShowErrorDialog("There is no view for the loaded item. It cannot be displayed.", new InvalidOperationException("No View Available"));
52        } catch (Exception ex) {
53          ErrorHandling.ShowErrorDialog((Control)MainFormManager.MainForm, "Cannot open file.", ex);
54        } finally {
55          ((MainForm.WindowsForms.MainForm)MainFormManager.MainForm).ResetAppStartingCursor();
56        }
57      }
58    }
59  }
60}
Note: See TracBrowser for help on using the repository browser.