[17331] | 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 {
|
---|
[17404] | 15 | internal static class FileManager {
|
---|
[17331] | 16 | private static OpenFileDialog openFileDialog;
|
---|
[17404] | 17 | private static ExportJsonDialog exportDialog = new ExportJsonDialog();
|
---|
[17331] | 18 |
|
---|
| 19 | public static void ExportJsonTemplate() {
|
---|
| 20 | IContentView activeView = MainFormManager.MainForm.ActiveView as IContentView;
|
---|
| 21 | if (activeView != null) {
|
---|
| 22 | ExportJsonTemplate(activeView);
|
---|
| 23 | }
|
---|
| 24 | }
|
---|
[17404] | 25 | public static void ExportJsonTemplate(IContentView view) {
|
---|
[17331] | 26 | IStorableContent content = view.Content as IStorableContent;
|
---|
| 27 | if (!view.Locked && content != null) {
|
---|
[17828] | 28 | if(content is IOptimizer) {
|
---|
| 29 | exportDialog.Content = content;
|
---|
| 30 | exportDialog.ShowDialog();
|
---|
| 31 | } else {
|
---|
| 32 | MessageBox.Show("This cannot item cannot be converted.", "Unsupported Item", MessageBoxButtons.OK);
|
---|
| 33 | }
|
---|
[17331] | 34 | }
|
---|
| 35 | }
|
---|
| 36 |
|
---|
| 37 |
|
---|
| 38 | public static void ImportJsonTemplate() {
|
---|
| 39 | if (openFileDialog == null) {
|
---|
| 40 | openFileDialog = new OpenFileDialog();
|
---|
| 41 | openFileDialog.Title = "Import .json-Template";
|
---|
| 42 | openFileDialog.FileName = "Item";
|
---|
| 43 | openFileDialog.Multiselect = false;
|
---|
| 44 | openFileDialog.DefaultExt = "json";
|
---|
| 45 | openFileDialog.Filter = ".json-Template|*.json|All Files|*.*";
|
---|
| 46 | }
|
---|
| 47 |
|
---|
| 48 | if (openFileDialog.ShowDialog() == DialogResult.OK) {
|
---|
| 49 | try {
|
---|
[17394] | 50 | var content = JsonTemplateInstantiator.Instantiate(openFileDialog.FileName);
|
---|
[17477] | 51 | IView view = MainFormManager.MainForm.ShowContent(content.Optimizer);
|
---|
[17331] | 52 | if (view == null)
|
---|
| 53 | ErrorHandling.ShowErrorDialog("There is no view for the loaded item. It cannot be displayed.", new InvalidOperationException("No View Available"));
|
---|
| 54 | } catch (Exception ex) {
|
---|
| 55 | ErrorHandling.ShowErrorDialog((Control)MainFormManager.MainForm, "Cannot open file.", ex);
|
---|
| 56 | } finally {
|
---|
| 57 | ((MainForm.WindowsForms.MainForm)MainFormManager.MainForm).ResetAppStartingCursor();
|
---|
| 58 | }
|
---|
| 59 | }
|
---|
| 60 | }
|
---|
| 61 | }
|
---|
| 62 | }
|
---|