Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 17591 was 17477, checked in by dpiringe, 5 years ago

#3026:

  • refactored JsonTemplateInstantiator -> now returns a InstantiatorResult which contains the optimizer and an IEnumerable of IResultJsonItem
  • code cleanup in JCGenerator
  • relocated the serialization of json items into IJsonItem with method GenerateJObject (virtual base implementation in JsonItem)
    • this allows custom serialization for json items (example: ValueLookupJsonItem)
    • items of interface IIntervalRestrictedJsonItem have a custom implementation of GenerateJObject -> hides Minimum and Maximum if the values are the physically min/max of their type
  • code cleanup in BaseConverter
File size: 2.1 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      IStorableContent content = view.Content as IStorableContent;
27      if (!view.Locked && content != null) {
28        exportDialog.Content = content;
29        exportDialog.ShowDialog();
30      }
31    }
32
33
34    public static void ImportJsonTemplate() {
35      if (openFileDialog == null) {
36        openFileDialog = new OpenFileDialog();
37        openFileDialog.Title = "Import .json-Template";
38        openFileDialog.FileName = "Item";
39        openFileDialog.Multiselect = false;
40        openFileDialog.DefaultExt = "json";
41        openFileDialog.Filter = ".json-Template|*.json|All Files|*.*";
42      }
43
44      if (openFileDialog.ShowDialog() == DialogResult.OK) {
45        try {
46          var content = JsonTemplateInstantiator.Instantiate(openFileDialog.FileName);
47          IView view = MainFormManager.MainForm.ShowContent(content.Optimizer);
48          if (view == null)
49            ErrorHandling.ShowErrorDialog("There is no view for the loaded item. It cannot be displayed.", new InvalidOperationException("No View Available"));
50        } catch (Exception ex) {
51          ErrorHandling.ShowErrorDialog((Control)MainFormManager.MainForm, "Cannot open file.", ex);
52        } finally {
53          ((MainForm.WindowsForms.MainForm)MainFormManager.MainForm).ResetAppStartingCursor();
54        }
55      }
56    }
57  }
58}
Note: See TracBrowser for help on using the repository browser.