Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2839_HiveProjectManagement/HeuristicLab.MainForm/3.3/Progress.cs @ 17357

Last change on this file since 17357 was 16057, checked in by jkarder, 6 years ago

#2839:

File size: 3.8 KB
RevLine 
[7582]1#region License Information
2/* HeuristicLab
[16057]3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[7582]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 System;
23
24namespace HeuristicLab.MainForm {
25  public class Progress : IProgress {
26    private string status;
27    public string Status {
[8165]28      get { return status; }
[7582]29      set {
[8165]30        if (status != value) {
31          status = value;
[7582]32          OnStatusChanged();
33        }
34      }
35    }
36
37    private double progressValue;
38    public double ProgressValue {
[8165]39      get { return progressValue; }
[7582]40      set {
[8165]41        if (progressValue != value) {
42          progressValue = value;
[7582]43          OnProgressChanged();
44        }
45      }
46    }
47
[8165]48    private ProgressState progressState;
49    public ProgressState ProgressState {
50      get { return progressState; }
[9894]51      private set {
[8165]52        if (progressState != value) {
53          progressState = value;
54          OnProgressStateChanged();
55        }
56      }
[7582]57    }
58
[8165]59    private bool canBeCanceled;
60    public bool CanBeCanceled {
61      get { return canBeCanceled; }
62      set {
63        if (canBeCanceled != value) {
64          canBeCanceled = value;
65          OnCanBeCanceledChanged();
66        }
67      }
[7582]68    }
69
[8165]70    public Progress() {
[9893]71      progressState = ProgressState.Finished;
72      canBeCanceled = false;
[8145]73    }
[16057]74    public Progress(string status)
75      : this() {
76      this.status = status;
77    }
78    public Progress(string status, ProgressState state)
79      : this() {
80      this.status = status;
81      this.progressState = state;
82    }
[8145]83
[9894]84    public void Cancel() {
[8165]85      if (canBeCanceled)
[9894]86        OnCancelRequested();
[8145]87    }
88
[8165]89    public void Finish() {
90      if (ProgressValue != 1.0) ProgressValue = 1.0;
91      ProgressState = ProgressState.Finished;
[7582]92    }
93
[9893]94    public void Start() {
[16057]95      ProgressValue = 0.0;
96      ProgressState = ProgressState.Started;
[9893]97    }
[16057]98
[9893]99    public void Start(string status) {
[16057]100      Start();
101      Status = status;
[9893]102    }
103
[8165]104    #region Event Handler
[7582]105    public event EventHandler StatusChanged;
106    private void OnStatusChanged() {
107      var handler = StatusChanged;
[9893]108      if (handler != null) handler(this, EventArgs.Empty);
[7582]109    }
110
111    public event EventHandler ProgressValueChanged;
112    private void OnProgressChanged() {
113      var handler = ProgressValueChanged;
[9893]114      if (handler != null) handler(this, EventArgs.Empty);
[7582]115    }
[8165]116
117    public event EventHandler ProgressStateChanged;
118    private void OnProgressStateChanged() {
119      var handler = ProgressStateChanged;
[9893]120      if (handler != null) handler(this, EventArgs.Empty);
[8165]121    }
122
123    public event EventHandler CanBeCanceledChanged;
124    private void OnCanBeCanceledChanged() {
125      var handler = CanBeCanceledChanged;
[9893]126      if (handler != null) handler(this, EventArgs.Empty);
[8165]127    }
128
[9894]129    public event EventHandler CancelRequested;
130    private void OnCancelRequested() {
[8165]131      var handler = CancelRequested;
[9893]132      if (handler != null) throw new NotSupportedException("Cancel request was ignored.");
[9894]133      else handler(this, EventArgs.Empty);
[8165]134    }
[7582]135    #endregion
136  }
137}
Note: See TracBrowser for help on using the repository browser.