Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OptimizationNetworks/HeuristicLab.Networks.Views/3.3/### obsolete/ClientNodeView.cs @ 14604

Last change on this file since 14604 was 11526, checked in by swagner, 10 years ago

#2205: Worked on optimization networks

File size: 3.1 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2014 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
22using HeuristicLab.MainForm;
23using HeuristicLab.PluginInfrastructure;
24using System;
25using System.Threading;
26using System.Windows.Forms;
27
28namespace HeuristicLab.Optimization.Networks.Views {
29  [View("ClientNode View")]
30  [Content(typeof(ClientNode), true)]
31  [Content(typeof(IClientNode), false)]
32  public partial class ClientNodeView : EntityView {
33    protected CancellationTokenSource tokenSource;
34    protected int openCalls = 0;
35
36    public new IClientNode Content {
37      get { return (IClientNode)base.Content; }
38      set { base.Content = value; }
39    }
40
41    public ClientNodeView() {
42      InitializeComponent();
43    }
44
45    protected override void OnContentChanged() {
46      base.OnContentChanged();
47
48      if (tokenSource != null) tokenSource.Cancel();
49
50      if (Content == null) {
51        tokenSource = null;
52        portCollectionView.Content = null;
53        serviceParameterCollectionCollectionView.Content = null;
54      } else {
55        tokenSource = new CancellationTokenSource();
56        portCollectionView.Content = Content.Ports;
57        serviceParameterCollectionCollectionView.Content = Content.Calls;
58      }
59    }
60
61    protected override void SetEnabledStateOfControls() {
62      base.SetEnabledStateOfControls();
63      callServicesButton.Enabled = Content != null && !ReadOnly;
64      cancelServicesButton.Enabled = Content != null && !ReadOnly && openCalls > 0;
65      portCollectionView.Enabled = Content != null && !ReadOnly;
66      serviceParameterCollectionCollectionView.Enabled = Content != null && !ReadOnly;
67    }
68
69    protected virtual void callServicesButton_Click(object sender, EventArgs e) {
70      openCalls++;
71      cancelServicesButton.Enabled = Content != null && !ReadOnly && openCalls > 0;
72      Content.CallServicesAsync(tokenSource.Token).ContinueWith(t => {
73        Invoke(new Action(() => {
74          openCalls--;
75          cancelServicesButton.Enabled = Content != null && !ReadOnly && openCalls > 0;
76
77          try {
78            t.Wait();
79          }
80          catch (Exception ex) {
81            ErrorHandling.ShowErrorDialog(this, ex);
82          }
83        }));
84      });
85    }
86    protected virtual void cancelServicesButton_Click(object sender, EventArgs e) {
87      tokenSource.Cancel();
88      tokenSource = new CancellationTokenSource();
89    }
90  }
91}
Note: See TracBrowser for help on using the repository browser.