Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PerformanceComparison/HeuristicLab.OptimizationExpertSystem/3.3/Views/ExpertSystemViewBase.cs @ 13718

Last change on this file since 13718 was 13718, checked in by abeham, 9 years ago

#2457: worked on expert system

File size: 2.6 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2016 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.Common;
23using HeuristicLab.Core.Views;
24using HeuristicLab.MainForm;
25using HeuristicLab.OptimizationExpertSystem.Common;
26using System;
27
28namespace HeuristicLab.OptimizationExpertSystem {
29  [View("Expert-System View")]
30  public partial class ExpertSystemViewBase : ItemView {
31    public OptimizationExpertSystem MainForm {
32      get { return (OptimizationExpertSystem)HeuristicLab.MainForm.MainFormManager.MainForm; }
33    }
34
35    public new ExpertSystem Content {
36      get { return (ExpertSystem)base.Content; }
37      set { base.Content = value; }
38    }
39
40    protected ExpertSystemViewBase() {
41      InitializeComponent();
42    }
43
44    protected override void RegisterContentEvents() {
45      base.RegisterContentEvents();
46      Content.DownloadStarted += ContentOnDownloadStarted;
47    }
48
49    protected override void DeregisterContentEvents() {
50      base.DeregisterContentEvents();
51      Content.DownloadStarted -= ContentOnDownloadStarted;
52    }
53
54    protected virtual void OnDownloadStarted() { }
55    protected virtual void OnDownloadEnded() { }
56
57    private void ContentOnDownloadStarted(object sender, EventArgs<IProgress> e) {
58      if (InvokeRequired) { Invoke((Action<object, EventArgs<IProgress>>)ContentOnDownloadStarted, sender, e); return; }
59      MainForm.AddOperationProgressToView(this, e.Value);
60      e.Value.ProgressStateChanged += ProgressOnStateChanged;
61      OnDownloadStarted();
62    }
63
64    private void ProgressOnStateChanged(object sender, EventArgs e) {
65      if (InvokeRequired) { Invoke((Action<object, EventArgs>)ProgressOnStateChanged, sender, e); return; }
66      var progress = (IProgress)sender;
67      if (progress == null || progress.ProgressState == ProgressState.Started) return;
68      OnDownloadEnded();
69    }
70  }
71}
Note: See TracBrowser for help on using the repository browser.