1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.IO;
|
---|
4 | using System.Linq;
|
---|
5 | using System.Text;
|
---|
6 | using System.Threading.Tasks;
|
---|
7 | using System.Windows.Forms;
|
---|
8 | using HeuristicLab.Common;
|
---|
9 | using HeuristicLab.Core;
|
---|
10 | using HeuristicLab.MainForm;
|
---|
11 | using HeuristicLab.Optimization;
|
---|
12 | using HeuristicLab.PluginInfrastructure;
|
---|
13 |
|
---|
14 | namespace 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 | }
|
---|