Changeset 8331 for branches/ScatterSearch (trunk integration)/HeuristicLab.Clients.OKB.Views/3.3/RunCreation/Views/OKBExperimentUploadView.cs
- Timestamp:
- 07/26/12 09:51:13 (12 years ago)
- Location:
- branches/ScatterSearch (trunk integration)
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ScatterSearch (trunk integration)
- Property svn:ignore
-
old new 21 21 protoc.exe 22 22 _ReSharper.HeuristicLab 3.3 Tests 23 Google.ProtocolBuffers-2.4.1.473.dll
-
- Property svn:mergeinfo changed
- Property svn:ignore
-
branches/ScatterSearch (trunk integration)/HeuristicLab.Clients.OKB.Views/3.3/RunCreation/Views/OKBExperimentUploadView.cs
r8086 r8331 35 35 namespace HeuristicLab.Clients.OKB.RunCreation { 36 36 [View("OKBExperimentUpload View")] 37 [Content(typeof(RunCollection), false)]38 37 [Content(typeof(IOptimizer), false)] 39 38 public partial class OKBExperimentUploadView : ItemView { 40 39 public new IOptimizer Content { 41 40 get { return (IOptimizer)base.Content; } 42 set { 43 base.Content = value; 44 } 41 set { base.Content = value; } 45 42 } 46 43 … … 58 55 Problem selectedProblem = null; 59 56 private ProgressView progressView; 57 private Progress progress; 60 58 61 59 public OKBExperimentUploadView() { 62 60 InitializeComponent(); 61 progress = new Progress() { 62 CanBeCanceled = false, 63 ProgressState = ProgressState.Finished 64 }; 63 65 } 64 66 … … 94 96 RunCreationClient.Instance.Refreshing += new EventHandler(RunCreationClient_Refreshing); 95 97 RunCreationClient.Instance.Refreshed += new EventHandler(RunCreationClient_Refreshed); 98 progressView = new ProgressView(this, progress); 96 99 } 97 100 … … 99 102 RunCreationClient.Instance.Refreshing -= new EventHandler(RunCreationClient_Refreshing); 100 103 RunCreationClient.Instance.Refreshed -= new EventHandler(RunCreationClient_Refreshed); 104 if (progressView != null) { 105 progressView.Content = null; 106 progressView.Dispose(); 107 progressView = null; 108 } 101 109 base.DeregisterContentEvents(); 102 110 } … … 108 116 private void DisplayRuns(RunCollection runs) { 109 117 if (RunCreationClient.Instance.Algorithms == null || RunCreationClient.Instance.Algorithms.Count() == 0) { 110 RunCreationClient.Instance.RefreshAsync(DisplayError); 118 Action a = new Action(delegate { 119 RunCreationClient.Instance.Refresh(); 120 CreateUI(runs); 121 }); 122 123 Task.Factory.StartNew(a).ContinueWith((t) => { DisplayError(t.Exception); }, TaskContinuationOptions.OnlyOnFaulted); 111 124 } else { 112 125 CreateUI(runs); … … 115 128 116 129 private void CreateUI(RunCollection runs) { 117 if (problems.Count == 0) 118 problems.AddRange(RunCreationClient.Instance.Problems); 119 if (algorithms.Count == 0) 120 algorithms.AddRange(RunCreationClient.Instance.Algorithms); 121 122 IItem algorithmType; 123 IItem problemType; 124 IItem algorithmName; 125 IItem problemName; 126 127 DataGridViewComboBoxColumn cmbAlgorithm = dataGridView.Columns[algorithmColumnIndex] as DataGridViewComboBoxColumn; 128 cmbAlgorithm.DataSource = algorithms; 129 cmbAlgorithm.DisplayMember = "Name"; 130 131 DataGridViewComboBoxColumn cmbProblem = dataGridView.Columns[problemColumnIndex] as DataGridViewComboBoxColumn; 132 cmbProblem.DataSource = problems; 133 cmbProblem.DisplayMember = "Name"; 134 135 foreach (IRun run in runs) { 136 int idx = dataGridView.Rows.Add(run.Name); 137 DataGridViewRow curRow = dataGridView.Rows[idx]; 138 curRow.Tag = run; 139 140 if (run.Parameters.TryGetValue(algorithmTypeParameterName, out algorithmType)) { 141 HeuristicLab.Data.StringValue algStr = algorithmType as HeuristicLab.Data.StringValue; 142 if (algStr != null) { 143 curRow.Cells[1].Value = algStr; 144 } 145 } 146 147 if (run.Parameters.TryGetValue(algorithmNameParameterName, out algorithmName)) { 148 HeuristicLab.Data.StringValue algStr = algorithmName as HeuristicLab.Data.StringValue; 149 if (algStr != null) { 150 curRow.Cells[2].Value = algStr; 151 } 152 } 153 154 if (run.Parameters.TryGetValue(problemTypeParameterName, out problemType)) { 155 HeuristicLab.Data.StringValue prbStr = problemType as HeuristicLab.Data.StringValue; 156 if (prbStr != null) { 157 curRow.Cells[4].Value = prbStr; 158 } 159 } 160 161 if (run.Parameters.TryGetValue(problemNameParameterName, out problemName)) { 162 HeuristicLab.Data.StringValue prbStr = problemName as HeuristicLab.Data.StringValue; 163 if (prbStr != null) { 164 curRow.Cells[5].Value = prbStr; 130 if (InvokeRequired) { 131 Invoke(new Action<RunCollection>(CreateUI), runs); 132 } else { 133 if (problems.Count == 0) 134 problems.AddRange(RunCreationClient.Instance.Problems); 135 if (algorithms.Count == 0) 136 algorithms.AddRange(RunCreationClient.Instance.Algorithms); 137 138 IItem algorithmType; 139 IItem problemType; 140 IItem algorithmName; 141 IItem problemName; 142 143 DataGridViewComboBoxColumn cmbAlgorithm = dataGridView.Columns[algorithmColumnIndex] as DataGridViewComboBoxColumn; 144 cmbAlgorithm.DataSource = algorithms; 145 cmbAlgorithm.DisplayMember = "Name"; 146 147 DataGridViewComboBoxColumn cmbProblem = dataGridView.Columns[problemColumnIndex] as DataGridViewComboBoxColumn; 148 cmbProblem.DataSource = problems; 149 cmbProblem.DisplayMember = "Name"; 150 151 foreach (IRun run in runs) { 152 int idx = dataGridView.Rows.Add(run.Name); 153 DataGridViewRow curRow = dataGridView.Rows[idx]; 154 curRow.Tag = run; 155 156 if (run.Parameters.TryGetValue(algorithmTypeParameterName, out algorithmType)) { 157 HeuristicLab.Data.StringValue algStr = algorithmType as HeuristicLab.Data.StringValue; 158 if (algStr != null) { 159 curRow.Cells[1].Value = algStr; 160 } 161 } 162 163 if (run.Parameters.TryGetValue(algorithmNameParameterName, out algorithmName)) { 164 HeuristicLab.Data.StringValue algStr = algorithmName as HeuristicLab.Data.StringValue; 165 if (algStr != null) { 166 curRow.Cells[2].Value = algStr; 167 } 168 } 169 170 if (run.Parameters.TryGetValue(problemTypeParameterName, out problemType)) { 171 HeuristicLab.Data.StringValue prbStr = problemType as HeuristicLab.Data.StringValue; 172 if (prbStr != null) { 173 curRow.Cells[4].Value = prbStr; 174 } 175 } 176 177 if (run.Parameters.TryGetValue(problemNameParameterName, out problemName)) { 178 HeuristicLab.Data.StringValue prbStr = problemName as HeuristicLab.Data.StringValue; 179 if (prbStr != null) { 180 curRow.Cells[5].Value = prbStr; 181 } 165 182 } 166 183 } … … 169 186 170 187 private void ClearRuns() { 171 dataGridView.Rows.Clear(); 172 runs.Clear(); 188 if (InvokeRequired) { 189 Invoke(new Action(ClearRuns)); 190 } else { 191 dataGridView.Rows.Clear(); 192 runs.Clear(); 193 } 173 194 } 174 195 … … 177 198 Invoke(new EventHandler(RunCreationClient_Refreshing), sender, e); 178 199 } else { 179 IProgress prog = new Progress(); 180 prog.Status = "Refreshing algorithms and problems..."; 181 SetProgressView(prog); 200 progress.Status = "Refreshing algorithms and problems..."; 201 progress.ProgressState = ProgressState.Started; 182 202 } 183 203 } … … 187 207 Invoke(new EventHandler(RunCreationClient_Refreshed), sender, e); 188 208 } else { 189 FinishProgressView();209 progress.Finish(); 190 210 SetEnabledStateOfControls(); 191 211 } … … 195 215 var task = System.Threading.Tasks.Task.Factory.StartNew(UploadAsync); 196 216 task.ContinueWith((t) => { 197 FinishProgressView();217 progress.Finish(); 198 218 PluginInfrastructure.ErrorHandling.ShowErrorDialog("An exception occured while uploading the runs to the OKB.", t.Exception); 199 219 }, TaskContinuationOptions.OnlyOnFaulted); … … 201 221 202 222 private void UploadAsync() { 203 IProgress prog = new Progress();204 prog .Status = "Uploading runs to OKB...";205 prog .ProgressValue = 0;223 progress.Status = "Uploading runs to OKB..."; 224 progress.ProgressValue = 0; 225 progress.ProgressState = ProgressState.Started; 206 226 double count = dataGridView.Rows.Count; 207 227 int i = 0; 208 209 SetProgressView(prog);210 228 foreach (DataGridViewRow row in dataGridView.Rows) { 211 229 selectedAlgorithm = algorithms.Where(x => x.Name == row.Cells[algorithmColumnIndex].Value.ToString()).FirstOrDefault(); … … 218 236 run.Store(); 219 237 i++; 220 prog.ProgressValue = ((double)i) / count; 221 } 222 FinishProgressView(); 223 } 224 225 private void SetProgressView(IProgress progress) { 226 if (InvokeRequired) { 227 Invoke(new Action<IProgress>(SetProgressView), progress); 228 } else { 229 if (progressView == null) { 230 progressView = new ProgressView(this, progress); 231 } else { 232 progressView.Progress = progress; 233 } 234 } 235 } 236 237 private void FinishProgressView() { 238 if (InvokeRequired) { 239 Invoke(new Action(FinishProgressView)); 240 } else { 241 if (progressView != null) { 242 progressView.Finish(); 243 progressView = null; 244 SetEnabledStateOfControls(); 245 ClearRuns(); 246 } 247 } 238 progress.ProgressValue = ((double)i) / count; 239 } 240 progress.Finish(); 241 ClearRuns(); 248 242 } 249 243
Note: See TracChangeset
for help on using the changeset viewer.