Changeset 9893
- Timestamp:
- 08/21/13 23:08:47 (11 years ago)
- Location:
- trunk/sources
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Clients.Access.Views/3.3/ClientViews/ClientView.cs
r9456 r9893 20 20 #endregion 21 21 22 using System;23 22 using HeuristicLab.Core.Views; 24 23 using HeuristicLab.MainForm; … … 34 33 } 35 34 36 private ProgressView progressView;37 private Progress progress;38 39 35 public ClientView() { 40 36 InitializeComponent(); 41 progress = new Progress() {42 CanBeCanceled = false,43 ProgressState = ProgressState.Finished44 };45 }46 47 protected override void DeregisterContentEvents() {48 if (progressView != null) {49 progressView.Content = null;50 progressView.Dispose();51 progressView = null;52 }53 base.DeregisterContentEvents();54 }55 56 protected override void RegisterContentEvents() {57 base.RegisterContentEvents();58 progressView = new ProgressView(this, progress);59 37 } 60 38 … … 98 76 99 77 public void StartProgressView() { 100 if (InvokeRequired) { 101 Invoke(new Action(StartProgressView)); 102 } else { 103 progress.Status = "Downloading client information. Please be patient."; 104 progress.ProgressState = ProgressState.Started; 105 } 78 var message = "Downloading client information. Please be patient."; 79 MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>().AddOperationProgressToView(this, message); 106 80 } 107 81 108 82 public void FinishProgressView() { 109 if (InvokeRequired) { 110 Invoke(new Action(FinishProgressView)); 111 } else { 112 progress.Finish(); 113 } 83 MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(this); 114 84 } 115 85 } -
trunk/sources/HeuristicLab.Clients.Hive.JobManager/3.3/Views/HiveResourceSelector.cs
r9456 r9893 64 64 imageList.Images.Add(HeuristicLab.Common.Resources.VSImageLibrary.MonitorLarge); 65 65 imageList.Images.Add(HeuristicLab.Common.Resources.VSImageLibrary.NetworkCenterLarge); 66 progress = new Progress() { 67 CanBeCanceled = false, 68 ProgressState = ProgressState.Finished 69 }; 66 progress = new Progress(); 70 67 } 71 68 72 69 protected override void DeregisterContentEvents() { 73 70 if (progressView != null) { 74 progressView.Content = null;75 71 progressView.Dispose(); 76 72 progressView = null; -
trunk/sources/HeuristicLab.Clients.Hive.JobManager/3.3/Views/RefreshableHiveJobListView.cs
r9540 r9893 50 50 this.itemsListView.ListViewItemSorter = new ListViewItemDateComparer(0, SortOrder.Ascending); 51 51 52 progress = new Progress() { 53 CanBeCanceled = false, 54 ProgressState = ProgressState.Finished 55 }; 52 progress = new Progress(); 56 53 progressView = new ProgressView(this, progress); 57 54 } … … 129 126 130 127 private void DeleteHiveJobsAsync(object items) { 131 progress.Status = "Deleting job..."; 132 progress.ProgressState = ProgressState.Started; 133 progress.ProgressValue = 0.0; 128 progress.Start("Deleting job..."); 134 129 foreach (RefreshableJob item in (List<RefreshableJob>)items) { 135 130 Content.Remove(item); … … 227 222 if (disposing) { 228 223 if (components != null) components.Dispose(); 229 progressView.Content = null;230 224 progressView.Dispose(); 225 progressView = null; 231 226 } 232 227 base.Dispose(disposing); -
trunk/sources/HeuristicLab.Clients.Hive.JobManager/3.3/Views/RefreshableHiveJobView.cs
r9710 r9893 42 42 [Content(typeof(RefreshableJob), true)] 43 43 public partial class RefreshableHiveJobView : HeuristicLab.Core.Views.ItemView { 44 private Progress progress;45 44 private ProgressView progressView; 46 45 private HiveResourceSelectorDialog hiveResourceSelectorDialog; … … 58 57 public RefreshableHiveJobView() { 59 58 InitializeComponent(); 60 progress = new Progress() {61 CanBeCanceled = false,62 ProgressState = ProgressState.Finished63 };64 59 } 65 60 … … 72 67 Content.ExceptionOccured += new EventHandler<EventArgs<Exception>>(Content_ExceptionOccured); 73 68 Content.StateLogListChanged += new EventHandler(Content_StateLogListChanged); 74 Content.IsProgressingChanged += new EventHandler(Content_IsProgressingChanged);75 69 Content.HiveTasksChanged += new EventHandler(Content_HiveTasksChanged); 76 70 Content.ExecutionStateChanged += new EventHandler(Content_ExecutionStateChanged); … … 78 72 Content.Loaded += new EventHandler(Content_Loaded); 79 73 Content.TaskReceived += new EventHandler(Content_TaskReceived); 80 progressView = new ProgressView(this, progress);74 progressView = new ProgressView(this, Content.Progress); 81 75 } 82 76 … … 88 82 Content.ExceptionOccured -= new EventHandler<EventArgs<Exception>>(Content_ExceptionOccured); 89 83 Content.StateLogListChanged -= new EventHandler(Content_StateLogListChanged); 90 Content.IsProgressingChanged -= new EventHandler(Content_IsProgressingChanged);91 84 Content.HiveTasksChanged -= new EventHandler(Content_HiveTasksChanged); 92 85 Content.ExecutionStateChanged -= new EventHandler(Content_ExecutionStateChanged); … … 95 88 Content.TaskReceived -= new EventHandler(Content_TaskReceived); 96 89 if (progressView != null) { 97 progressView.Content = null;98 90 progressView.Dispose(); 99 91 progressView = null; … … 159 151 Content_HiveExperimentChanged(this, EventArgs.Empty); 160 152 Content_HiveTasksChanged(this, EventArgs.Empty); 161 Content_IsProgressingChanged(this, EventArgs.Empty);162 153 Content_StateLogListChanged(this, EventArgs.Empty); 163 154 HiveExperiment_PropertyChanged(this, new PropertyChangedEventArgs("Id")); … … 336 327 if (Content != null && Content.Job != null) { 337 328 RegisterHiveExperimentEvents(); 338 Content_IsProgressingChanged(sender, e);339 329 } 340 330 } … … 410 400 var task = System.Threading.Tasks.Task.Factory.StartNew(ResumeJobAsync, Content); 411 401 task.ContinueWith((t) => { 412 progress.Finish();402 Content.Progress.Finish(); 413 403 MessageBox.Show("An error occured resuming the job. See the log for more information.", "HeuristicLab Hive Job Manager", MessageBoxButtons.OK, MessageBoxIcon.Error); 414 404 Content.Log.LogException(t.Exception); … … 422 412 var task = System.Threading.Tasks.Task.Factory.StartNew(PauseJobAsync, Content); 423 413 task.ContinueWith((t) => { 424 progress.Finish();414 Content.Progress.Finish(); 425 415 MessageBox.Show("An error occured pausing the job. See the log for more information.", "HeuristicLab Hive Job Manager", MessageBoxButtons.OK, MessageBoxIcon.Error); 426 416 Content.Log.LogException(t.Exception); … … 431 421 var task = System.Threading.Tasks.Task.Factory.StartNew(StopJobAsync, Content); 432 422 task.ContinueWith((t) => { 433 progress.Finish();423 Content.Progress.Finish(); 434 424 MessageBox.Show("An error occured stopping the job. See the log for more information.", "HeuristicLab Hive Job Manager", MessageBoxButtons.OK, MessageBoxIcon.Error); 435 425 Content.Log.LogException(t.Exception); … … 439 429 440 430 private void PauseJobAsync(object job) { 441 progress.Status = "Pausing job..."; 442 progress.ProgressState = ProgressState.Started; 431 Content.Progress.Start("Pausing job..."); 443 432 HiveClient.PauseJob((RefreshableJob)job); 444 progress.Finish();433 Content.Progress.Finish(); 445 434 } 446 435 447 436 private void StopJobAsync(object job) { 448 progress.Status = "Stopping job..."; 449 progress.ProgressState = ProgressState.Started; 437 Content.Progress.Start("Stopping job..."); 450 438 HiveClient.StopJob((RefreshableJob)job); 451 progress.Finish();439 Content.Progress.Finish(); 452 440 } 453 441 454 442 private void ResumeJobAsync(object job) { 455 progress.Status = "Resuming job..."; 456 progress.ProgressState = ProgressState.Started; 443 Content.Progress.Start("Resuming job..."); 457 444 HiveClient.ResumeJob((RefreshableJob)job); 458 progress.Finish();445 Content.Progress.Finish(); 459 446 } 460 447 … … 507 494 stopButton.Enabled = Content.IsControllable && Content.ExecutionState == ExecutionState.Started && !Content.IsProgressing; 508 495 resetButton.Enabled = false; 509 }510 }511 #endregion512 513 #region Progress reporting514 private void Content_IsProgressingChanged(object sender, EventArgs e) {515 if (this.InvokeRequired) {516 Invoke(new EventHandler(Content_IsProgressingChanged), sender, e);517 } else {518 if (Content != null && Content.Progress != null && Content.IsProgressing) {519 progressView.Content = Content.Progress;520 } else if (Content != null) {521 progressView.Content = progress;522 }523 496 } 524 497 } -
trunk/sources/HeuristicLab.Clients.Hive.Views/3.3/HiveTasks/OptimizerHiveTaskView.cs
r9456 r9893 45 45 public OptimizerHiveTaskView() { 46 46 InitializeComponent(); 47 progress = new Progress() { 48 CanBeCanceled = false, 49 ProgressState = ProgressState.Finished 50 }; 47 progress = new Progress(); 51 48 } 52 49 … … 70 67 Content.IsControllableChanged -= new EventHandler(Content_IsControllableChanged); 71 68 if (progressView != null) { 72 progressView.Content = null;73 69 progressView.Dispose(); 74 70 progressView = null; … … 110 106 111 107 private void PauseTaskAsync() { 112 progress.Status = "Pausing task. Please be patient for the command to take effect."; 113 progress.ProgressState = ProgressState.Started; 108 progress.Start("Pausing task. Please be patient for the command to take effect."); 114 109 Content.Pause(); 115 110 progress.Finish(); … … 117 112 118 113 private void StopTaskAsync() { 119 progress.Status = "Stopping task. Please be patient for the command to take effect."; 120 progress.ProgressState = ProgressState.Started; 114 progress.Start("Stopping task. Please be patient for the command to take effect."); 121 115 Content.Stop(); 122 116 progress.Finish(); … … 124 118 125 119 private void ResumeTaskAsync() { 126 progress.Status = "Resuming task. Please be patient for the command to take effect."; 127 progress.ProgressState = ProgressState.Started; 120 progress.Start("Resuming task. Please be patient for the command to take effect."); 128 121 Content.Restart(); 129 122 progress.Finish(); -
trunk/sources/HeuristicLab.Clients.Hive/3.3/HiveClient.cs
r9456 r9893 265 265 try { 266 266 refreshableJob.IsProgressing = true; 267 refreshableJob.Progress = new Progress("Connecting to server...");267 refreshableJob.Progress.Start("Connecting to server..."); 268 268 IEnumerable<string> resourceNames = ToResourceNameList(refreshableJob.Job.ResourceNames); 269 269 var resourceIds = new List<Guid>(); … … 424 424 var hiveExperiment = refreshableJob.Job; 425 425 refreshableJob.IsProgressing = true; 426 refreshableJob.Progress = new Progress();427 426 TaskDownloader downloader = null; 428 427 … … 431 430 IEnumerable<LightweightTask> allTasks; 432 431 433 refreshableJob.Progress.Status = "Connecting to Server...";434 432 // fetch all task objects to create the full tree of tree of HiveTask objects 435 refreshableJob.Progress.Sta tus = "Downloading list of tasks...";433 refreshableJob.Progress.Start("Downloading list of tasks..."); 436 434 allTasks = HiveServiceLocator.Instance.CallHiveService(s => s.GetLightweightJobTasksWithoutStateLog(hiveExperiment.Id)); 437 435 totalJobCount = allTasks.Count(); -
trunk/sources/HeuristicLab.Clients.Hive/3.3/RefreshableJob.cs
r9456 r9893 178 178 #region Constructors and Cloning 179 179 public RefreshableJob() { 180 this.progress = new Progress(); 180 181 this.refreshAutomatically = false; 181 182 this.Job = new Job(); … … 186 187 } 187 188 public RefreshableJob(Job hiveJob) { 189 this.progress = new Progress(); 188 190 this.refreshAutomatically = true; 189 191 this.Job = hiveJob; -
trunk/sources/HeuristicLab.Clients.OKB.Views/3.3/RunCreation/Views/OKBExperimentUploadView.cs
r9456 r9893 59 59 public OKBExperimentUploadView() { 60 60 InitializeComponent(); 61 progress = new Progress() { 62 CanBeCanceled = false, 63 ProgressState = ProgressState.Finished 64 }; 61 progress = new Progress(); 65 62 } 66 63 … … 103 100 RunCreationClient.Instance.Refreshed -= new EventHandler(RunCreationClient_Refreshed); 104 101 if (progressView != null) { 105 progressView.Content = null;106 102 progressView.Dispose(); 107 103 progressView = null; -
trunk/sources/HeuristicLab.MainForm.WindowsForms/3.3/Controls/ProgressView.cs
r9868 r9893 21 21 22 22 using System; 23 using System.ComponentModel;24 23 using System.Windows.Forms; 25 24 26 25 namespace HeuristicLab.MainForm.WindowsForms { 27 [View("ProgressView")] 28 [Content(typeof(IProgress), true)] 29 public partial class ProgressView : AsynchronousContentView { 30 private const int DefaultCancelTimeoutMs = 3000; 31 private readonly IView view; 32 33 [Category("Custom"), Description("The time that the process is allowed to exit.")] 34 [DefaultValue(DefaultCancelTimeoutMs)] 35 public int CancelTimeoutMs { get; set; } 36 private bool ShouldSerializeCancelTimeoutMs() { return CancelTimeoutMs != DefaultCancelTimeoutMs; } 37 38 public new IProgress Content { 39 get { return (IProgress)base.Content; } 40 set { base.Content = value; } 26 public sealed partial class ProgressView : UserControl { 27 private readonly Control control; 28 public Control Control { 29 get { return control; } 41 30 } 42 31 43 private Control Control { 44 get { return (Control)view; } 32 private readonly IProgress content; 33 public IProgress Content { 34 get { return content; } 45 35 } 46 36 47 public bool DisposeOnFinish { get; set; } 37 public ProgressView(Control control, IProgress content) 38 : base() { 39 if (control == null) throw new ArgumentNullException("control", "The control is null."); 40 if (content == null) throw new ArgumentNullException("content", "The passed progress is null."); 41 InitializeComponent(); 48 42 49 public ProgressView() { 50 InitializeComponent(); 43 this.control = control; 44 this.content = content; 45 if (content.ProgressState == ProgressState.Started) 46 ShowProgress(); 47 RegisterContentEvents(); 51 48 } 52 49 53 p ublic ProgressView(IView view)54 : this() {55 if (view == null) throw new ArgumentNullException("view", "The view is null.");56 if (!(view is Control)) throw new ArgumentException("The view is not a control.", "view");57 this.view = view;50 private void RegisterContentEvents() { 51 content.StatusChanged += new EventHandler(progress_StatusChanged); 52 content.ProgressValueChanged += new EventHandler(progress_ProgressValueChanged); 53 content.ProgressStateChanged += new EventHandler(Content_ProgressStateChanged); 54 content.CanBeCanceledChanged += new EventHandler(Content_CanBeCanceledChanged); 58 55 } 59 public ProgressView(IView view, IProgress progress) 60 : this(view) { 61 Content = progress; 62 } 63 64 public static ProgressView Attach(IView view, IProgress progress, bool disposeOnFinish = false) { 65 return new ProgressView(view, progress) { 66 DisposeOnFinish = disposeOnFinish 67 }; 68 } 69 70 protected override void RegisterContentEvents() { 71 Content.StatusChanged += new EventHandler(progress_StatusChanged); 72 Content.ProgressValueChanged += new EventHandler(progress_ProgressValueChanged); 73 Content.ProgressStateChanged += new EventHandler(Content_ProgressStateChanged); 74 Content.CanBeCanceledChanged += new EventHandler(Content_CanBeCanceledChanged); 75 base.RegisterContentEvents(); 76 } 77 78 protected override void DeregisterContentEvents() { 79 base.DeregisterContentEvents(); 80 Content.StatusChanged -= new EventHandler(progress_StatusChanged); 81 Content.ProgressValueChanged -= new EventHandler(progress_ProgressValueChanged); 82 Content.ProgressStateChanged -= new EventHandler(Content_ProgressStateChanged); 83 Content.CanBeCanceledChanged -= new EventHandler(Content_CanBeCanceledChanged); 84 } 85 86 protected override void OnContentChanged() { 87 base.OnContentChanged(); 88 if (Content == null) { 89 HideProgress(); 90 } else { 91 if (Content.ProgressState == ProgressState.Started) 92 ShowProgress(); 93 } 94 } 95 96 protected override void SetEnabledStateOfControls() { 97 base.SetEnabledStateOfControls(); 98 cancelButton.Visible = Content != null && Content.CanBeCanceled; 99 cancelButton.Enabled = Content != null && Content.CanBeCanceled && !ReadOnly; 56 private void DeregisterContentEvents() { 57 content.StatusChanged -= new EventHandler(progress_StatusChanged); 58 content.ProgressValueChanged -= new EventHandler(progress_ProgressValueChanged); 59 content.ProgressStateChanged -= new EventHandler(Content_ProgressStateChanged); 60 content.CanBeCanceledChanged -= new EventHandler(Content_CanBeCanceledChanged); 100 61 } 101 62 102 63 private void ShowProgress() { 103 if (InvokeRequired) Invoke((Action)ShowProgress); 104 else { 105 if (view != null) { 106 Left = (Control.ClientRectangle.Width / 2) - (Width / 2); 107 Top = (Control.ClientRectangle.Height / 2) - (Height / 2); 108 Anchor = AnchorStyles.None; 64 if (Control.InvokeRequired) { 65 Control.Invoke((Action)ShowProgress); 66 return; 67 } 68 Left = (Control.ClientRectangle.Width / 2) - (Width / 2); 69 Top = (Control.ClientRectangle.Height / 2) - (Height / 2); 70 Anchor = AnchorStyles.None; 109 71 110 LockBackground();111 112 113 } 114 115 116 Visible = true;117 }72 control.Enabled = false; 73 Parent = Control.Parent; 74 BringToFront(); 75 76 UpdateProgressValue(); 77 UpdateProgressStatus(); 78 UpdateCancelButton(); 79 Visible = true; 118 80 } 119 81 … … 121 83 if (InvokeRequired) Invoke((Action)HideProgress); 122 84 else { 123 if (view != null) { 124 Parent = null; 125 UnlockBackground(); 126 } 85 control.Enabled = true; 86 Parent = null; 127 87 Visible = false; 128 88 } … … 138 98 139 99 private void Content_ProgressStateChanged(object sender, EventArgs e) { 140 switch (Content.ProgressState) { 141 case ProgressState.Finished: 142 HideProgress(); 143 if (DisposeOnFinish) { 144 Content = null; 145 Dispose(); 146 } 147 break; 100 switch (content.ProgressState) { 101 case ProgressState.Finished: HideProgress(); break; 148 102 case ProgressState.Canceled: HideProgress(); break; 149 103 case ProgressState.Started: ShowProgress(); break; 104 default: throw new NotSupportedException("The progress state " + content.ProgressState + " is not supported by the ProgressView."); 150 105 } 151 106 } 152 107 153 108 private void Content_CanBeCanceledChanged(object sender, EventArgs e) { 154 SetEnabledStateOfControls();109 UpdateCancelButton(); 155 110 } 156 111 157 private void LockBackground() { 158 if (InvokeRequired) Invoke((Action)LockBackground); 159 else { 160 view.Enabled = false; 161 } 162 } 163 164 private void UnlockBackground() { 165 if (InvokeRequired) Invoke((Action)UnlockBackground); 166 else { 167 view.Enabled = true; 168 } 112 private void UpdateCancelButton() { 113 cancelButton.Visible = content != null && content.CanBeCanceled; 114 cancelButton.Enabled = content != null && content.CanBeCanceled; 169 115 } 170 116 … … 172 118 if (InvokeRequired) Invoke((Action)UpdateProgressValue); 173 119 else { 174 if ( Content != null) {175 double progressValue = Content.ProgressValue;120 if (content != null) { 121 double progressValue = content.ProgressValue; 176 122 if (progressValue <= 0.0 || progressValue > 1.0) { 177 if (progressBar.Style != ProgressBarStyle.Marquee) 178 progressBar.Style = ProgressBarStyle.Marquee; 123 progressBar.Style = ProgressBarStyle.Marquee; 179 124 } else { 180 if (progressBar.Style != ProgressBarStyle.Blocks) 181 progressBar.Style = ProgressBarStyle.Blocks; 125 progressBar.Style = ProgressBarStyle.Blocks; 182 126 progressBar.Value = (int)Math.Round(progressBar.Minimum + progressValue * (progressBar.Maximum - progressBar.Minimum)); 183 127 } … … 188 132 private void UpdateProgressStatus() { 189 133 if (InvokeRequired) Invoke((Action)UpdateProgressStatus); 190 else if ( Content != null)191 statusLabel.Text = Content.Status;134 else if (content != null) 135 statusLabel.Text = content.Status; 192 136 } 193 137 194 138 private void cancelButton_Click(object sender, EventArgs e) { 195 if (Content != null) { 196 try { 197 Content.Cancel(CancelTimeoutMs); 198 ReadOnly = true; 199 cancelButtonTimer.Interval = CancelTimeoutMs; 200 cancelButtonTimer.Start(); 201 } catch (NotSupportedException nse) { 202 PluginInfrastructure.ErrorHandling.ShowErrorDialog(nse); 203 } 204 } 205 } 206 207 private void cancelButtonTimer_Tick(object sender, EventArgs e) { 208 cancelButtonTimer.Stop(); 209 if (Visible) ReadOnly = false; 139 content.Cancel(); 210 140 } 211 141 } -
trunk/sources/HeuristicLab.MainForm.WindowsForms/3.3/Controls/ProgressView.designer.cs
r9456 r9893 32 32 /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> 33 33 protected override void Dispose(bool disposing) { 34 DeregisterContentEvents(); 34 35 if (disposing && (components != null)) { 35 36 components.Dispose(); … … 50 51 this.cancelButton = new System.Windows.Forms.Button(); 51 52 this.panel = new System.Windows.Forms.Panel(); 52 this.cancelButtonTimer = new System.Windows.Forms.Timer(this.components);53 53 this.panel.SuspendLayout(); 54 54 this.SuspendLayout(); … … 97 97 this.panel.TabIndex = 3; 98 98 // 99 // cancelButtonTimer100 //101 this.cancelButtonTimer.Tick += new System.EventHandler(this.cancelButtonTimer_Tick);102 //103 99 // ProgressView 104 100 // … … 109 105 this.panel.ResumeLayout(false); 110 106 this.ResumeLayout(false); 111 112 107 } 113 108 … … 118 113 private System.Windows.Forms.Button cancelButton; 119 114 private System.Windows.Forms.Panel panel; 120 private System.Windows.Forms.Timer cancelButtonTimer;121 115 } 122 116 } -
trunk/sources/HeuristicLab.MainForm.WindowsForms/3.3/MainForms/MainForm.cs
r9865 r9893 30 30 namespace HeuristicLab.MainForm.WindowsForms { 31 31 public partial class MainForm : Form, IMainForm { 32 private readonly Dictionary<IContent, IProgress> contentProgressLookup;33 private readonly Dictionary<IView, IProgress> viewProgressLookup;34 32 private bool initialized; 35 33 private int appStartingCursors; … … 41 39 this.views = new Dictionary<IView, Form>(); 42 40 this.userInterfaceItems = new List<IUserInterfaceItem>(); 43 this.contentProgressLookup = new Dictionary<IContent, IProgress>();44 this.viewProgressLookup = new Dictionary<IView, IProgress>();45 41 this.initialized = false; 46 42 this.showContentInViewHost = false; … … 347 343 CloseView(view, closeReason); 348 344 } 345 #endregion 346 347 #region progress views 348 private readonly Dictionary<IContent, IProgress> contentProgressLookup = new Dictionary<IContent, IProgress>(); 349 private readonly Dictionary<IView, IProgress> viewProgressLookup = new Dictionary<IView, IProgress>(); 350 private readonly List<ProgressView> progressViews = new List<ProgressView>(); 349 351 350 352 /// <summary> … … 355 357 throw new ArgumentException("A progress is already registered for the specified content.", "content"); 356 358 357 var contentViews = Enumerable.Empty<IContentView>(); 359 var contentViews = views.Keys.OfType<ContentView>(); 360 if (!contentViews.Any(v => v.Content == content)) 361 throw new ArgumentException("The content is not displayed in a top-level view", "content"); 362 358 363 if (addToObjectGraphObjects) { 359 364 var containedObjects = content.GetObjectGraphObjects(); 360 contentViews = views.Keys.OfType<IContentView>().Where(v => containedObjects.Contains(v.Content));365 contentViews = contentViews.Where(v => containedObjects.Contains(v.Content)); 361 366 } else 362 contentViews = views.Keys.OfType<IContentView>().Where(v => v.Content == content); 363 364 var progress = new Progress(progressMessage); 365 foreach (var contentView in contentViews) 366 ProgressView.Attach(contentView, progress, true); 367 contentViews = contentViews.Where(v => v.Content == content); 368 369 var progress = new Progress(progressMessage, ProgressState.Started); 370 foreach (var contentView in contentViews) { 371 progressViews.Add(new ProgressView((Control)contentView, progress)); 372 } 367 373 368 374 contentProgressLookup[content] = progress; … … 376 382 throw new ArgumentException("A progress is already registered for the specified view.", "view"); 377 383 378 var progress = new Progress(progressMessage); 379 ProgressView.Attach(view, progress, true); 384 var control = view as Control; 385 if (control == null) throw new ArgumentException("The passed view must be a control.", "view"); 386 387 var progress = new Progress(progressMessage, ProgressState.Started); 388 progressViews.Add(new ProgressView(control, progress)); 380 389 viewProgressLookup[view] = progress; 381 390 } … … 390 399 391 400 progress.Finish(); 401 foreach (var progressView in progressViews.Where(v => v.Content == progress).ToList()) { 402 progressView.Dispose(); 403 progressViews.Remove(progressView); 404 } 392 405 contentProgressLookup.Remove(content); 393 406 } … … 402 415 403 416 progress.Finish(); 417 foreach (var progressView in progressViews.Where(v => v.Content == progress).ToList()) { 418 progressView.Dispose(); 419 progressViews.Remove(progressView); 420 } 404 421 viewProgressLookup.Remove(view); 405 422 } -
trunk/sources/HeuristicLab.MainForm/3.3/Interfaces/IProgress.cs
r9849 r9893 55 55 /// <exception cref="NotSupportedException">Thrown when cancellation is not supported.</exception> 56 56 /// <param name="timeoutMs">The operation is given a certain timeout to cancel. If the operation doesn't cancel in this time it will be forcibly closed.</param> 57 void Cancel(int timeoutMs );57 void Cancel(int timeoutMs = 0); 58 58 /// <summary> 59 59 /// Sets the ProgressValue to 1 and the ProgressState to Finished. 60 60 /// </summary> 61 61 void Finish(); 62 63 void Start(string status); 64 65 void Start(); 62 66 63 67 /// <summary> -
trunk/sources/HeuristicLab.MainForm/3.3/Progress.cs
r9849 r9893 70 70 71 71 public Progress() { 72 progressState = ProgressState.Started; 72 progressState = ProgressState.Finished; 73 canBeCanceled = false; 73 74 } 74 75 public Progress(string status) … … 76 77 this.status = status; 77 78 } 78 public Progress(string status, double progressValue) 79 : this(status) { 80 this.progressValue = progressValue; 79 public Progress(string status, ProgressState state) 80 : this() { 81 this.status = status; 82 this.progressState = state; 81 83 } 82 84 83 public void Cancel(int timeoutMs ) {85 public void Cancel(int timeoutMs = 0) { 84 86 if (canBeCanceled) 85 87 OnCancelRequested(timeoutMs); … … 91 93 } 92 94 95 public void Start() { 96 ProgressValue = 0.0; 97 ProgressState = ProgressState.Started; 98 } 99 100 public void Start(string status) { 101 Start(); 102 Status = status; 103 } 104 93 105 #region Event Handler 94 106 public event EventHandler StatusChanged; 95 107 private void OnStatusChanged() { 96 108 var handler = StatusChanged; 97 try { 98 if (handler != null) handler(this, EventArgs.Empty); 99 } catch { } 109 if (handler != null) handler(this, EventArgs.Empty); 100 110 } 101 111 … … 103 113 private void OnProgressChanged() { 104 114 var handler = ProgressValueChanged; 105 try { 106 if (handler != null) handler(this, EventArgs.Empty); 107 } catch { } 115 if (handler != null) handler(this, EventArgs.Empty); 108 116 } 109 117 … … 111 119 private void OnProgressStateChanged() { 112 120 var handler = ProgressStateChanged; 113 try { 114 if (handler != null) handler(this, EventArgs.Empty); 115 } catch { } 121 if (handler != null) handler(this, EventArgs.Empty); 116 122 } 117 123 … … 119 125 private void OnCanBeCanceledChanged() { 120 126 var handler = CanBeCanceledChanged; 121 try { 122 if (handler != null) handler(this, EventArgs.Empty); 123 } catch { } 127 if (handler != null) handler(this, EventArgs.Empty); 128 124 129 } 125 130 … … 127 132 private void OnCancelRequested(int timeoutMs) { 128 133 var handler = CancelRequested; 129 try { 130 if (handler == null) throw new NotSupportedException("Cancel request was ignored."); 131 else handler(this, new EventArgs<int>(timeoutMs)); 132 } catch { } 134 if (handler != null) throw new NotSupportedException("Cancel request was ignored."); 135 else handler(this, new EventArgs<int>(timeoutMs)); 133 136 } 134 137 #endregion
Note: See TracChangeset
for help on using the changeset viewer.