1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2011 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
4 | *
|
---|
5 | * This file is part of HeuristicLab.
|
---|
6 | *
|
---|
7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
8 | * it under the terms of the GNU General Public License as published by
|
---|
9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
10 | * (at your option) any later version.
|
---|
11 | *
|
---|
12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | * GNU General Public License for more details.
|
---|
16 | *
|
---|
17 | * You should have received a copy of the GNU General Public License
|
---|
18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
19 | */
|
---|
20 | #endregion
|
---|
21 |
|
---|
22 | using System;
|
---|
23 | using System.Linq;
|
---|
24 | using System.ServiceModel.Security;
|
---|
25 | using System.Windows.Forms;
|
---|
26 | using HeuristicLab.Collections;
|
---|
27 | using HeuristicLab.MainForm;
|
---|
28 | using HeuristicLab.MainForm.WindowsForms;
|
---|
29 | using HeuristicLab.PluginInfrastructure;
|
---|
30 |
|
---|
31 | namespace HeuristicLab.Clients.Hive.JobManager.Views {
|
---|
32 | /// <summary>
|
---|
33 | /// The base class for visual representations of items.
|
---|
34 | /// </summary>
|
---|
35 | [View("Hive Job Manager")]
|
---|
36 | [Content(typeof(HiveClient), true)]
|
---|
37 | public partial class HiveJobManagerView : AsynchronousContentView {
|
---|
38 |
|
---|
39 | public new HiveClient Content {
|
---|
40 | get { return (HiveClient)base.Content; }
|
---|
41 | set { base.Content = value; }
|
---|
42 | }
|
---|
43 |
|
---|
44 | /// <summary>
|
---|
45 | /// Initializes a new instance of <see cref="ItemBaseView"/>.
|
---|
46 | /// </summary>
|
---|
47 | public HiveJobManagerView() {
|
---|
48 | InitializeComponent();
|
---|
49 | }
|
---|
50 |
|
---|
51 | protected override void RegisterContentEvents() {
|
---|
52 | base.RegisterContentEvents();
|
---|
53 | Content.Refreshing += new EventHandler(Content_Refreshing);
|
---|
54 | Content.Refreshed += new EventHandler(Content_Refreshed);
|
---|
55 | Content.HiveExperimentsChanged += new EventHandler(Content_HiveExperimentsChanged);
|
---|
56 |
|
---|
57 | }
|
---|
58 |
|
---|
59 | protected override void DeregisterContentEvents() {
|
---|
60 | Content.Refreshing -= new EventHandler(Content_Refreshing);
|
---|
61 | Content.Refreshed -= new EventHandler(Content_Refreshed);
|
---|
62 | Content.HiveExperimentsChanged -= new EventHandler(Content_HiveExperimentsChanged);
|
---|
63 | base.DeregisterContentEvents();
|
---|
64 | }
|
---|
65 |
|
---|
66 | protected override void OnContentChanged() {
|
---|
67 | base.OnContentChanged();
|
---|
68 | if (Content == null) {
|
---|
69 | hiveExperimentListView.Content = null;
|
---|
70 | } else {
|
---|
71 | hiveExperimentListView.Content = Content.Jobs;
|
---|
72 | if (Content != null)
|
---|
73 | Content.RefreshAsync(new Action<Exception>((Exception ex) => HandleServiceException(ex)));
|
---|
74 | }
|
---|
75 | }
|
---|
76 |
|
---|
77 | protected override void SetEnabledStateOfControls() {
|
---|
78 | base.SetEnabledStateOfControls();
|
---|
79 | refreshButton.Enabled = Content != null;
|
---|
80 | hiveExperimentListView.Enabled = Content != null;
|
---|
81 | }
|
---|
82 |
|
---|
83 | private void Content_Refreshing(object sender, EventArgs e) {
|
---|
84 | if (InvokeRequired) {
|
---|
85 | Invoke(new EventHandler(Content_Refreshing), sender, e);
|
---|
86 | } else {
|
---|
87 | Cursor = Cursors.AppStarting;
|
---|
88 | refreshButton.Enabled = false;
|
---|
89 | hiveExperimentListView.Enabled = false;
|
---|
90 | }
|
---|
91 | }
|
---|
92 | private void Content_Refreshed(object sender, EventArgs e) {
|
---|
93 | if (InvokeRequired) {
|
---|
94 | Invoke(new EventHandler(Content_Refreshed), sender, e);
|
---|
95 | } else {
|
---|
96 | hiveExperimentListView.Content = Content.Jobs;
|
---|
97 | refreshButton.Enabled = true;
|
---|
98 | hiveExperimentListView.Enabled = true;
|
---|
99 | Cursor = Cursors.Default;
|
---|
100 | }
|
---|
101 | }
|
---|
102 |
|
---|
103 | private void refreshButton_Click(object sender, EventArgs e) {
|
---|
104 | Content.RefreshAsync(new Action<Exception>((Exception ex) => HandleServiceException(ex)));
|
---|
105 | }
|
---|
106 |
|
---|
107 | private void HandleServiceException(Exception ex) {
|
---|
108 | if (ex is MessageSecurityException) {
|
---|
109 | MessageBox.Show("A Message Security error has occured. This normally means that your user name or password is wrong.", "HeuristicLab Hive Administrator", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
---|
110 | } else {
|
---|
111 | ErrorHandling.ShowErrorDialog(this, "Refresh failed.", ex);
|
---|
112 | }
|
---|
113 | }
|
---|
114 |
|
---|
115 | protected override void OnClosing(FormClosingEventArgs e) {
|
---|
116 | base.OnClosing(e);
|
---|
117 | if (Content != null && Content.Jobs != null) {
|
---|
118 | foreach (var exp in Content.Jobs.OfType<RefreshableJob>()) {
|
---|
119 | if (exp.RefreshAutomatically) {
|
---|
120 | exp.RefreshAutomatically = false; // stop result polling
|
---|
121 | }
|
---|
122 | }
|
---|
123 | }
|
---|
124 | }
|
---|
125 |
|
---|
126 | private void HiveExperiments_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<RefreshableJob> e) {
|
---|
127 | foreach (var item in e.Items) {
|
---|
128 | HiveClient.Delete(item);
|
---|
129 | }
|
---|
130 | }
|
---|
131 |
|
---|
132 | private void Content_HiveExperimentsChanged(object sender, EventArgs e) {
|
---|
133 | Content.Jobs.ItemsRemoved += new CollectionItemsChangedEventHandler<RefreshableJob>(HiveExperiments_ItemsRemoved);
|
---|
134 | }
|
---|
135 | }
|
---|
136 | }
|
---|