Changeset 10020 for stable/HeuristicLab.Problems.Instances.Views
- Timestamp:
- 10/02/13 17:04:43 (11 years ago)
- Location:
- stable
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
stable
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Problems.Instances.Views/3.3/ProblemInstanceProviderViewGeneric.cs
r9456 r10020 21 21 22 22 using System; 23 using System.ComponentModel; 23 24 using System.Linq; 25 using System.Threading.Tasks; 24 26 using System.Windows.Forms; 25 27 using HeuristicLab.MainForm; … … 88 90 89 91 private void instancesComboBox_SelectionChangeCommitted(object sender, System.EventArgs e) { 92 toolTip.SetToolTip(instancesComboBox, String.Empty); 90 93 if (instancesComboBox.SelectedIndex >= 0) { 91 94 var descriptor = (IDataDescriptor)instancesComboBox.SelectedItem; 92 T instance = Content.LoadData(descriptor); 93 try { 94 GenericConsumer.Load(instance); 95 } catch (Exception ex) { 96 ErrorHandling.ShowErrorDialog(String.Format("This problem does not support loading the instance {0}", descriptor.Name), ex); 97 } 98 toolTip.SetToolTip(instancesComboBox, descriptor.Description); 99 } else toolTip.SetToolTip(instancesComboBox, String.Empty); 95 96 IContentView activeView = (IContentView)MainFormManager.MainForm.ActiveView; 97 var mainForm = (MainForm.WindowsForms.MainForm)MainFormManager.MainForm; 98 // lock active view and show progress bar 99 mainForm.AddOperationProgressToContent(activeView.Content, "Loading problem instance."); 100 // continuation for removing the progess bar from the active view 101 Action<Task> removeProgressFromContent = (_) => mainForm.RemoveOperationProgressFromContent(activeView.Content); 102 103 // task structure: 104 // loadFromProvider 105 // | 106 // +-> on fault -> show error dialog -> remove progress bar 107 // | 108 // `-> success -> loadToProblem 109 // | 110 // +-> on fault -> show error dialog -> remove progress bar 111 // | 112 // `-> success -> set tool tip -> remove progress bar 113 var loadFromProvider = new Task<T>(() => Content.LoadData(descriptor)); 114 115 // success 116 var loadToProblem = loadFromProvider 117 .ContinueWith(task => GenericConsumer.Load(task.Result), TaskContinuationOptions.OnlyOnRanToCompletion); 118 // on error 119 loadFromProvider 120 .ContinueWith(task => { ErrorHandling.ShowErrorDialog(String.Format("Could not load the problem instance {0}", descriptor.Name), task.Exception); }, TaskContinuationOptions.OnlyOnFaulted) 121 .ContinueWith(removeProgressFromContent); 122 123 // success 124 loadToProblem 125 .ContinueWith(task => toolTip.SetToolTip(instancesComboBox, descriptor.Description), TaskContinuationOptions.OnlyOnRanToCompletion) 126 .ContinueWith(removeProgressFromContent); 127 // on error 128 loadToProblem.ContinueWith(task => { ErrorHandling.ShowErrorDialog(String.Format("This problem does not support loading the instance {0}", descriptor.Name), task.Exception); }, TaskContinuationOptions.OnlyOnFaulted) 129 .ContinueWith(removeProgressFromContent); 130 131 // start async loading task 132 loadFromProvider.Start(); 133 } 100 134 } 101 135 }
Note: See TracChangeset
for help on using the changeset viewer.