Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OKB/HeuristicLab.OKB.Cockpit.Admin/OperatorGraphEditorHost.xaml.cs @ 5593

Last change on this file since 5593 was 4311, checked in by swagner, 14 years ago

Integrated OKB clients for HL 3.3 (#1166)

File size: 2.7 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Windows.Controls;
6using System.Windows;
7using HeuristicLab.BackgroundProcessing;
8using System.IO;
9using HeuristicLab.Persistence.Default.Xml;
10using HeuristicLab.Persistence.Core;
11using HeuristicLab.PluginInfrastructure;
12
13namespace 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}
Note: See TracBrowser for help on using the repository browser.