#region License Information /* HeuristicLab * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using HeuristicLab.MainForm; using HeuristicLab.PluginInfrastructure; using System; using System.Threading; using System.Windows.Forms; namespace HeuristicLab.Optimization.Networks.Views { [View("ClientNode View")] [Content(typeof(ClientNode), true)] [Content(typeof(IClientNode), false)] public partial class ClientNodeView : EntityView { protected CancellationTokenSource tokenSource; protected int openCalls = 0; public new IClientNode Content { get { return (IClientNode)base.Content; } set { base.Content = value; } } public ClientNodeView() { InitializeComponent(); } protected override void OnContentChanged() { base.OnContentChanged(); if (tokenSource != null) tokenSource.Cancel(); if (Content == null) { tokenSource = null; portCollectionView.Content = null; serviceParameterCollectionCollectionView.Content = null; } else { tokenSource = new CancellationTokenSource(); portCollectionView.Content = Content.Ports; serviceParameterCollectionCollectionView.Content = Content.Calls; } } protected override void SetEnabledStateOfControls() { base.SetEnabledStateOfControls(); callServicesButton.Enabled = Content != null && !ReadOnly; cancelServicesButton.Enabled = Content != null && !ReadOnly && openCalls > 0; portCollectionView.Enabled = Content != null && !ReadOnly; serviceParameterCollectionCollectionView.Enabled = Content != null && !ReadOnly; } protected virtual void callServicesButton_Click(object sender, EventArgs e) { openCalls++; cancelServicesButton.Enabled = Content != null && !ReadOnly && openCalls > 0; Content.CallServicesAsync(tokenSource.Token).ContinueWith(t => { Invoke(new Action(() => { openCalls--; cancelServicesButton.Enabled = Content != null && !ReadOnly && openCalls > 0; try { t.Wait(); } catch (Exception ex) { ErrorHandling.ShowErrorDialog(this, ex); } })); }); } protected virtual void cancelServicesButton_Click(object sender, EventArgs e) { tokenSource.Cancel(); tokenSource = new CancellationTokenSource(); } } }