Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3.3-Hive/sources/HeuristicLab.Hive/HeuristicLab.Hive.Experiment.Views/3.3/ProgressView.cs @ 4368

Last change on this file since 4368 was 4368, checked in by cneumuel, 14 years ago
  • created HiveClient which shows an overview over all submitted HiveExperiments
  • its possible to download all submitted HiveExperiments including results
  • Experiments are now sent as a whole to the Hive and the Hive-Slaves take care of creating child-jobs (if necessary). The parent job is then paused and will be reactivated when all child-jobs are finished
  • WcfService-Clients are now consistently managed by WcfServicePool which allows to use IDisposable-Pattern and always keeps exactly one proxy-object until all callers disposed them.
  • created ProgressView which is able to lock a View and display progress of an action. It also allows to simulate progress if no progress-information is available so that users don't get too nervous while waiting.
File size: 4.1 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Drawing;
5using System.Data;
6using System.Linq;
7using System.Text;
8using HeuristicLab.MainForm.WindowsForms;
9using System.Windows.Forms;
10using System.Diagnostics;
11
12namespace HeuristicLab.Hive.Experiment.Views {
13  public partial class ProgressView : HeuristicLab.MainForm.WindowsForms.View {
14    private ContentView parentView = null;
15    private bool simulateProgress = false;
16
17    public bool CancelEnabled {
18      get {
19        return cancelButton.Visible;
20      }
21      set {
22        if (InvokeRequired) {
23          Invoke(new Action<bool>((ce) => { CancelEnabled = ce; }), value);
24        } else {
25          cancelButton.Visible = value;
26        }
27      }
28    }
29
30    private string status;
31    public string Status {
32      get { return status; }
33      set {
34        if (InvokeRequired) {
35          Invoke(new Action<string>((s) => { Status = s;}), value);
36        } else {
37          status = value;
38          statusLabel.Text = status;
39        }
40       
41      }
42    }
43
44    public ProgressView(ContentView parentView)
45      : this(parentView, "", false, true) {
46    }
47
48    public ProgressView(ContentView parentView, string initialStatus)
49      : this(parentView, initialStatus, false, true) {
50    }
51
52    public ProgressView(ContentView parentView, string initialStatus, bool simulateProgress)
53      : this(parentView, initialStatus, simulateProgress, true) {
54    }
55
56    /// <param name="parentView">This is the View which will be locked if lockParentView is true</param>
57    /// <param name="initialStatus">Status message</param>
58    /// <param name="simulateProgress">If true, the progress will be simulated by a timer which addes some progress every second</param>
59    /// <param name="lockParentView">if true parentView will be locked</param>
60    public ProgressView(ContentView parentView, string initialStatus, bool simulateProgress, bool lockParentView) {
61      InitializeComponent();
62      this.parentView = parentView;
63      this.CancelEnabled = false;
64      this.Status = initialStatus;
65      this.simulateProgress = simulateProgress;
66
67      if (simulateProgress) {
68        Timer progressSimulator = new Timer();
69        progressSimulator.Interval = 2000;
70        progressSimulator.Tick += new EventHandler(progressSimulator_Tick);
71        progressSimulator.Start();
72      }
73
74      this.Left = (parentView.ClientRectangle.Width / 2) - (this.Width / 2);
75      this.Top = (parentView.ClientRectangle.Height / 2) - (this.Height / 2);
76      this.Anchor = AnchorStyles.Left | AnchorStyles.Top;
77
78      if (lockParentView)
79        LockBackground();
80
81      parentView.Controls.Add(this);
82      this.BringToFront();
83    }
84
85    private void progressSimulator_Tick(object sender, EventArgs e) {
86      progressBar.Value = Math.Min(progressBar.Value + (progressBar.Maximum - progressBar.Value) / 10 + 1, progressBar.Maximum - 1);
87    }
88
89    private void LockBackground() {
90      this.parentView.Locked = true;
91      foreach (Control c in this.parentView.Controls) {
92        c.Enabled = false;
93      }
94      this.Enabled = true;
95      this.ReadOnly = false;
96    }
97
98    public void SetProgress(double progress) {
99      if (InvokeRequired) {
100        Invoke(new Action<double>(SetProgress), progress);
101      } else {
102        this.progressBar.Value = Math.Max(this.progressBar.Value, (int)(progress * progressBar.Maximum));
103      }
104    }
105
106    public void Finish() {
107      if (InvokeRequired) {
108        Invoke(new Action(Finish));
109      } else {
110        progressBar.Value = progressBar.Maximum;
111        parentView.Locked = false;
112        foreach (Control c in this.parentView.Controls) {
113          c.Enabled = true;
114        }
115        parentView.Controls.Remove(this);
116        this.Dispose();
117      }
118    }
119
120    private void cancelButton_Click(object sender, EventArgs e) {
121      Finish();
122    }
123
124    public event EventHandler Canceled;
125    protected virtual void OnCanceled() {
126      var handler = Canceled;
127      if (handler != null) Canceled(this, EventArgs.Empty);
128    }
129  }
130}
Note: See TracBrowser for help on using the repository browser.