1 | using System;
|
---|
2 | using System.Windows.Forms;
|
---|
3 | using HeuristicLab.Common;
|
---|
4 | using HeuristicLab.MainForm;
|
---|
5 | using HeuristicLab.Optimization;
|
---|
6 | using HeuristicLab.PluginInfrastructure;
|
---|
7 |
|
---|
8 | namespace 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 | }
|
---|