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 | 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 | }
|
---|