[4311] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 | using System.Linq;
|
---|
| 4 | using System.Text;
|
---|
| 5 | using System.Windows.Controls;
|
---|
| 6 | using System.Windows;
|
---|
| 7 | using HeuristicLab.BackgroundProcessing;
|
---|
| 8 | using System.IO;
|
---|
| 9 | using HeuristicLab.Persistence.Default.Xml;
|
---|
| 10 | using HeuristicLab.Persistence.Core;
|
---|
| 11 | using HeuristicLab.PluginInfrastructure;
|
---|
| 12 |
|
---|
| 13 | namespace HeuristicLab.OKB.Cockpit.Admin {
|
---|
| 14 |
|
---|
| 15 | public partial class OperatorGraphEditorHost : UserControl {
|
---|
| 16 |
|
---|
| 17 | public enum EditorType { Algorithm, Problem };
|
---|
| 18 |
|
---|
| 19 | private IOperatorGraphEditor activeEditor;
|
---|
| 20 | private Dictionary<string, IOperatorGraphEditor> availableEditors;
|
---|
| 21 |
|
---|
| 22 | public OperatorGraphEditorHost() {
|
---|
| 23 | InitializeComponent();
|
---|
| 24 | availableEditors = ApplicationManager.Manager
|
---|
| 25 | .GetInstances<IOperatorGraphEditor>()
|
---|
| 26 | .ToDictionary(e => e.PlatformName, e => e);
|
---|
| 27 | }
|
---|
| 28 |
|
---|
| 29 | public void LoadData(byte[] data, OKBAdmin.Platform platform, EditorType type) {
|
---|
| 30 | availableEditors.TryGetValue(platform.Name, out activeEditor);
|
---|
| 31 | if (activeEditor == null) {
|
---|
| 32 | MessageBox.Show(
|
---|
| 33 | String.Format("Unsupported platform '{0}'", platform.Name),
|
---|
| 34 | typeof(OperatorGraphEditorHost).Name,
|
---|
| 35 | MessageBoxButton.OK, MessageBoxImage.Error);
|
---|
| 36 | return;
|
---|
| 37 | }
|
---|
| 38 | try {
|
---|
| 39 | activeEditor.Load(data);
|
---|
| 40 | } catch (Exception x) {
|
---|
| 41 | MessageBox.Show(
|
---|
| 42 | String.Format("Could not load {0} implementation:\n{1}", platform.Name, x.ToString()),
|
---|
| 43 | typeof(OperatorGraphEditorHost).Name,
|
---|
| 44 | MessageBoxButton.OK, MessageBoxImage.Error);
|
---|
| 45 | }
|
---|
| 46 | try {
|
---|
| 47 | Dispatcher.Invoke(new Action(() => {
|
---|
| 48 | if (type == EditorType.Algorithm) {
|
---|
| 49 | FormsHost.Child = activeEditor.CreateAlgorithmControl();
|
---|
| 50 | } else {
|
---|
| 51 | FormsHost.Child = activeEditor.CreateProblemControl();
|
---|
| 52 | }
|
---|
| 53 | }));
|
---|
| 54 | } catch (Exception x) {
|
---|
| 55 | MessageBox.Show(
|
---|
| 56 | String.Format("Could not instatiate operator graph editor:\n{1}", x.ToString()),
|
---|
| 57 | typeof(OperatorGraphEditorHost).Name,
|
---|
| 58 | MessageBoxButton.OK, MessageBoxImage.Error);
|
---|
| 59 | }
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | public byte[] GetAlgorithmData() {
|
---|
| 63 | return (byte[])Dispatcher.Invoke(new Func<System.Windows.Forms.Control, byte[]>(control => {
|
---|
| 64 | if (activeEditor == null) return null;
|
---|
| 65 | return activeEditor.GetAlgorithmData(control);
|
---|
| 66 | }), FormsHost.Child);
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 | public byte[] GetProblemData() {
|
---|
| 70 | return (byte[])Dispatcher.Invoke(new Func<System.Windows.Forms.Control, byte[]>(control => {
|
---|
| 71 | if (activeEditor == null) return null;
|
---|
| 72 | return activeEditor.GetProblemData(control);
|
---|
| 73 | }), FormsHost.Child);
|
---|
| 74 | }
|
---|
| 75 | }
|
---|
| 76 | }
|
---|