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