Changeset 16235 for branches/2931_OR-Tools_LP_MIP/HeuristicLab.Clients.Hive.Administrator/3.3/Views/ProjectJobsView.cs
- Timestamp:
- 10/18/18 14:07:32 (6 years ago)
- Location:
- branches/2931_OR-Tools_LP_MIP
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2931_OR-Tools_LP_MIP
- Property svn:mergeinfo changed
/branches/2916_IndexedDataTableSerialization (added) merged: 15918 /trunk merged: 16168-16169,16177,16179,16184-16187,16202-16209,16211,16213,16216,16218-16219,16221,16223-16224,16232
- Property svn:mergeinfo changed
-
branches/2931_OR-Tools_LP_MIP/HeuristicLab.Clients.Hive.Administrator
- Property svn:mergeinfo changed
/trunk/HeuristicLab.Clients.Hive.Administrator merged: 16184-16187,16202,16205,16208-16209,16211
- Property svn:mergeinfo changed
-
branches/2931_OR-Tools_LP_MIP/HeuristicLab.Clients.Hive.Administrator/3.3/Views/ProjectJobsView.cs
r16139 r16235 24 24 using System.Drawing; 25 25 using System.Linq; 26 using System.Threading.Tasks; 26 27 using System.Windows.Forms; 27 28 using HeuristicLab.MainForm; … … 30 31 using HeuristicLab.Data; 31 32 using HeuristicLab.Clients.Hive.Views; 33 using HeuristicLab.Core; 32 34 33 35 namespace HeuristicLab.Clients.Hive.Administrator.Views { … … 41 43 private const string JOB_DATECREATED = "Date Created"; 42 44 private const string JOB_STATE = "State"; 45 private const string JOB_EXECUTIONSTATE = "Execution State"; 46 private const string JOB_EXECUTIONTIME = "Execution Time"; 43 47 private const string JOB_DESCRIPTION = "Description"; 44 48 private const string JOB_TASKCOUNT = "Tasks"; 49 private const string JOB_WAITINGTASKCOUNT = "Waiting"; 45 50 private const string JOB_CALCULATINGTASKCOUNT = "Calculating"; 46 51 private const string JOB_FINISHEDTASKCOUNT = "Finished"; 47 48 52 49 53 private readonly Color onlineStatusColor = Color.FromArgb(255, 189, 249, 143); // #bdf98f … … 53 57 private readonly Color deletionPendingStatusColor2 = Color.FromArgb(255, 249, 149, 143); // #f9958f 54 58 59 private IProgress progress; 60 public IProgress Progress { 61 get { return progress; } 62 set { 63 this.progress = value; 64 OnIsProgressingChanged(); 65 } 66 } 67 55 68 public new Project Content { 56 69 get { return (Project)base.Content; } … … 60 73 public ProjectJobsView() { 61 74 InitializeComponent(); 62 63 removeButton.Enabled = false; 75 progress = new Progress(); 76 77 removeButton.Enabled = false; 78 } 79 80 protected override void RegisterContentEvents() { 81 base.RegisterContentEvents(); 64 82 matrixView.DataGridView.SelectionChanged += DataGridView_SelectionChanged; 83 MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>().AddOperationProgressToView(this, progress); 84 } 85 86 protected override void DeregisterContentEvents() { 87 matrixView.DataGridView.SelectionChanged -= DataGridView_SelectionChanged; 88 MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(this, false); 89 base.DeregisterContentEvents(); 65 90 } 66 91 67 92 private void DataGridView_SelectionChanged(object sender, EventArgs e) { 68 if (matrixView.DataGridView.SelectedRows == null || matrixView.DataGridView.SelectedRows.Count == 0) return; 69 70 bool anyDeletable = false; 71 foreach (DataGridViewRow r in matrixView.DataGridView.SelectedRows) { 72 if (((string)r.Cells[0].Value) == JobState.Online.ToString()) anyDeletable = true; 73 } 74 75 removeButton.Enabled = anyDeletable; 93 SetEnabledStateOfControls(); 76 94 } 77 95 … … 81 99 removeButton.Enabled = false; 82 100 UpdateJobs(); 83 } 101 SetEnabledStateOfControls(); 102 } 103 84 104 protected override void SetEnabledStateOfControls() { 85 105 base.SetEnabledStateOfControls(); 86 106 bool enabled = Content != null && !Locked && !ReadOnly; 87 107 88 refreshButton.Enabled = enabled;89 removeButton.Enabled = false;90 108 matrixView.Enabled = enabled; 91 } 109 110 // Buttons (start/resume, pause, stop, remove) 111 refreshButton.Enabled = startButton.Enabled = pauseButton.Enabled = stopButton.Enabled = removeButton.Enabled = false; 112 113 if (enabled && progress.ProgressState != ProgressState.Started) { 114 var jobs = GetSelectedJobs().ToList(); 115 if (jobs.Any()) { 116 117 startButton.Enabled = jobs.All(x => 118 !x.IsProgressing && HiveAdminClient.Instance.Tasks.ContainsKey(x.Id) && HiveAdminClient.Instance.Tasks[x.Id].Count > 0 119 && x.Job.ProjectId != Guid.Empty //&& x.Job.ResourceIds != null && x.Job.ResourceIds.Any() 120 && (x.ExecutionState == ExecutionState.Prepared || x.ExecutionState == ExecutionState.Paused)); 121 pauseButton.Enabled = jobs.All(x => !x.IsProgressing && x.ExecutionState == ExecutionState.Started); 122 stopButton.Enabled = jobs.All(x => !x.IsProgressing && (x.ExecutionState == ExecutionState.Started || x.ExecutionState == ExecutionState.Paused)); 123 removeButton.Enabled = jobs.All(x => !x.IsProgressing && x.Job.State == JobState.Online); 124 } 125 } 126 127 // refresh Button 128 if (Content != null && !Locked && progress.ProgressState != ProgressState.Started) { 129 refreshButton.Enabled = true; 130 } 131 } 132 92 133 #endregion Overrides 93 134 … … 98 139 99 140 private void refreshButton_Click(object sender, EventArgs e) { 100 RefreshJobs(); 101 } 102 103 private async void removeButton_Click(object sender, EventArgs e) { 104 if (matrixView.DataGridView.SelectedRows == null || matrixView.DataGridView.SelectedRows.Count == 0) return; 105 106 var jobNamesToDelete = new List<string>(); 107 var jobIdsToDelete = new List<Guid>(); 108 foreach (DataGridViewRow r in matrixView.DataGridView.SelectedRows) { 109 if(((string)r.Cells[0].Value) == JobState.Online.ToString()) { 110 jobNamesToDelete.Add(" - " + ((string)r.Cells[3].Value)); 111 jobIdsToDelete.Add(Guid.Parse((string)r.Cells[8].Value)); 112 } 113 } 114 115 if(jobIdsToDelete.Any()) { 141 progress.Start("Refreshing jobs..."); 142 SetEnabledStateOfControls(); 143 var task = System.Threading.Tasks.Task.Factory.StartNew(RefreshJobsAsync); 144 145 task.ContinueWith((t) => { 146 progress.Finish(); 147 SetEnabledStateOfControls(); 148 }); 149 } 150 151 private void removeButton_Click(object sender, EventArgs e) { 152 var jobs = GetSelectedJobs(); 153 154 if (jobs.Any()) { 116 155 var result = MessageBox.Show("Do you really want to remove following job(s):\n\n" 117 + String.Join("\n", jobNamesToDelete),156 + String.Join("\n", jobs.Select(x => x.Job.Name)), 118 157 "HeuristicLab Hive Administrator", 119 158 MessageBoxButtons.YesNo, … … 121 160 122 161 if (result == DialogResult.Yes) { 123 await SecurityExceptionUtil.TryAsyncAndReportSecurityExceptions( 124 action: () => { 125 DeleteJobs(jobIdsToDelete); 126 }, 127 finallyCallback: () => { 128 matrixView.DataGridView.ClearSelection(); 129 removeButton.Enabled = false; 130 RefreshJobs(); 131 }); 132 } 133 } 134 } 135 162 progress.Start("Removing job(s)..."); 163 SetEnabledStateOfControls(); 164 var task = System.Threading.Tasks.Task.Factory.StartNew(RemoveJobsAsync, jobs); 165 166 task.ContinueWith((t) => { 167 RefreshJobs(); 168 progress.Finish(); 169 SetEnabledStateOfControls(); 170 }, TaskContinuationOptions.NotOnFaulted); 171 172 task.ContinueWith((t) => { 173 RefreshJobs(); 174 progress.Finish(); 175 SetEnabledStateOfControls(); 176 MessageBox.Show("An error occured removing the job(s).", "HeuristicLab Hive Administrator", MessageBoxButtons.OK, MessageBoxIcon.Error); 177 }, TaskContinuationOptions.OnlyOnFaulted); 178 } 179 } 180 } 181 182 private void startButton_Click(object sender, EventArgs e) { 183 var jobs = GetSelectedJobs(); 184 185 if (jobs.Any()) { 186 var result = MessageBox.Show("Do you really want to resume following job(s):\n\n" 187 + String.Join("\n", jobs.Select(x => x.Job.Name)), 188 "HeuristicLab Hive Administrator", 189 MessageBoxButtons.YesNo, 190 MessageBoxIcon.Question); 191 192 if (result == DialogResult.Yes) { 193 progress.Start("Resuming job(s)..."); 194 SetEnabledStateOfControls(); 195 var task = System.Threading.Tasks.Task.Factory.StartNew(ResumeJobsAsync, jobs); 196 197 task.ContinueWith((t) => { 198 RefreshJobs(); 199 progress.Finish(); 200 SetEnabledStateOfControls(); 201 }, TaskContinuationOptions.NotOnFaulted); 202 203 task.ContinueWith((t) => { 204 RefreshJobs(); 205 progress.Finish(); 206 SetEnabledStateOfControls(); 207 MessageBox.Show("An error occured resuming the job(s).", "HeuristicLab Hive Administrator", MessageBoxButtons.OK, MessageBoxIcon.Error); 208 }, TaskContinuationOptions.OnlyOnFaulted); 209 } 210 } 211 } 212 213 private void pauseButton_Click(object sender, EventArgs e) { 214 var jobs = GetSelectedJobs(); 215 216 if (jobs.Any()) { 217 var result = MessageBox.Show("Do you really want to pause following job(s):\n\n" 218 + String.Join("\n", jobs.Select(x => x.Job.Name)), 219 "HeuristicLab Hive Administrator", 220 MessageBoxButtons.YesNo, 221 MessageBoxIcon.Question); 222 223 if (result == DialogResult.Yes) { 224 progress.Start("Pausing job(s)..."); 225 SetEnabledStateOfControls(); 226 var task = System.Threading.Tasks.Task.Factory.StartNew(PauseJobsAsync, jobs); 227 228 task.ContinueWith((t) => { 229 RefreshJobs(); 230 progress.Finish(); 231 SetEnabledStateOfControls(); 232 }, TaskContinuationOptions.NotOnFaulted); 233 234 task.ContinueWith((t) => { 235 RefreshJobs(); 236 progress.Finish(); 237 SetEnabledStateOfControls(); 238 MessageBox.Show("An error occured pausing the job(s).", "HeuristicLab Hive Administrator", MessageBoxButtons.OK, MessageBoxIcon.Error); 239 }, TaskContinuationOptions.OnlyOnFaulted); 240 } 241 } 242 } 243 244 private void stopButton_Click(object sender, EventArgs e) { 245 var jobs = GetSelectedJobs(); 246 247 if (jobs.Any()) { 248 var result = MessageBox.Show("Do you really want to stop following job(s):\n\n" 249 + String.Join("\n", jobs.Select(x => x.Job.Name)), 250 "HeuristicLab Hive Administrator", 251 MessageBoxButtons.YesNo, 252 MessageBoxIcon.Question); 253 254 if (result == DialogResult.Yes) { 255 progress.Start("Stopping job(s)..."); 256 SetEnabledStateOfControls(); 257 var task = System.Threading.Tasks.Task.Factory.StartNew(StopJobsAsync, jobs); 258 259 task.ContinueWith((t) => { 260 RefreshJobs(); 261 progress.Finish(); 262 SetEnabledStateOfControls(); 263 }, TaskContinuationOptions.NotOnFaulted); 264 265 task.ContinueWith((t) => { 266 RefreshJobs(); 267 progress.Finish(); 268 SetEnabledStateOfControls(); 269 MessageBox.Show("An error occured stopping the job(s).", "HeuristicLab Hive Administrator", MessageBoxButtons.OK, MessageBoxIcon.Error); 270 }, TaskContinuationOptions.OnlyOnFaulted); 271 } 272 } 273 } 274 275 public event EventHandler IsProgressingChanged; 276 private void OnIsProgressingChanged() { 277 var handler = IsProgressingChanged; 278 if (handler != null) handler(this, EventArgs.Empty); 279 } 136 280 #endregion Event Handlers 137 281 138 282 #region Helpers 283 284 private IEnumerable<RefreshableJob> GetSelectedJobs() { 285 if (Content == null || matrixView.DataGridView.SelectedRows == null || matrixView.DataGridView.SelectedRows.Count == 0) 286 return Enumerable.Empty<RefreshableJob>() ; 287 288 var jobs = new List<RefreshableJob>(); 289 foreach (DataGridViewRow r in matrixView.DataGridView.SelectedRows) { 290 if (((string)r.Cells[0].Value) == JobState.Online.ToString()) { 291 jobs.Add(HiveAdminClient.Instance.Jobs[Content.Id].FirstOrDefault(x => x.Id == Guid.Parse((string) r.Cells[11].Value))); 292 } 293 } 294 295 return jobs; 296 } 297 139 298 private void RefreshJobs() { 140 299 HiveAdminClient.Instance.RefreshJobs(); 141 300 UpdateJobs(); 301 SetEnabledStateOfControls(); 142 302 } 143 303 … … 148 308 var jobs = HiveAdminClient.Instance.Jobs[Content.Id]; 149 309 var resources = HiveAdminClient.Instance.Resources; 150 string[,] values = new string[jobs.Count, 1 0];310 string[,] values = new string[jobs.Count, 13]; 151 311 152 312 for(int i = 0; i < jobs.Count; i++) { 153 var job = jobs.ElementAt(i); 154 155 values[i, 0] = job.State.ToString(); 156 values[i, 1] = job.DateCreated.ToString(); 157 values[i, 2] = job.OwnerUsername; 158 values[i, 3] = job.Name; 159 values[i, 4] = job.JobCount.ToString(); 160 values[i, 5] = job.CalculatingCount.ToString(); 161 values[i, 6] = job.FinishedCount.ToString(); 162 values[i, 7] = job.Description; 163 values[i, 8] = job.Id.ToString(); 164 values[i, 9] = job.OwnerUserId.ToString(); 313 var job = jobs.ElementAt(i); 314 values[i, 0] = job.Job.State.ToString(); 315 values[i, 1] = job.ExecutionState.ToString(); 316 values[i, 2] = job.ExecutionTime.ToString(); 317 values[i, 3] = job.Job.DateCreated.ToString(); 318 values[i, 4] = job.Job.OwnerUsername; 319 values[i, 5] = job.Job.Name; 320 values[i, 6] = job.Job.JobCount.ToString(); 321 values[i, 7] = (job.Job.JobCount - job.Job.CalculatingCount - job.Job.FinishedCount).ToString(); 322 values[i, 8] = job.Job.CalculatingCount.ToString(); 323 values[i, 9] = job.Job.FinishedCount.ToString(); 324 values[i, 10] = job.Job.Description; 325 values[i, 11] = job.Job.Id.ToString(); 326 values[i, 12] = job.Job.OwnerUserId.ToString(); 165 327 } 166 328 167 329 var matrix = new StringMatrix(values); 168 matrix.ColumnNames = new string[] { JOB_STATE, JOB_ DATECREATED, JOB_OWNER, JOB_NAME, JOB_TASKCOUNT, JOB_CALCULATINGTASKCOUNT, JOB_FINISHEDTASKCOUNT, JOB_DESCRIPTION, JOB_ID, JOB_OWNERID };330 matrix.ColumnNames = new string[] { JOB_STATE, JOB_EXECUTIONSTATE, JOB_EXECUTIONTIME, JOB_DATECREATED, JOB_OWNER, JOB_NAME, JOB_TASKCOUNT, JOB_WAITINGTASKCOUNT, JOB_CALCULATINGTASKCOUNT, JOB_FINISHEDTASKCOUNT, JOB_DESCRIPTION, JOB_ID, JOB_OWNERID }; 169 331 matrix.SortableView = true; 170 332 return matrix; … … 193 355 matrixView.DataGridView.Columns[1].MinimumWidth = 108; 194 356 } 195 } else { 196 refreshButton.Enabled = false; 197 removeButton.Enabled = false; 198 matrixView.Content = null; 199 } 200 } 201 } 202 203 private void DeleteJobs(List<Guid> jobIds) { 204 try { 205 HiveAdminClient.DeleteJobs(jobIds); 206 } catch (AnonymousUserException) { 207 ShowHiveInformationDialog(); 208 } 357 } 358 } 359 } 360 361 private void RefreshJobsAsync() { 362 HiveAdminClient.Instance.RefreshJobs(); 363 UpdateJobs(); 364 } 365 366 private void ResumeJobsAsync(object jobs) { 367 var jobList = (IEnumerable<RefreshableJob>)jobs; 368 foreach (var job in jobList) { 369 progress.Status = "Resuming job \"" + job.Job.Name + "\"..."; 370 HiveAdminClient.ResumeJob(job); 371 } 372 } 373 374 private void PauseJobsAsync(object jobs) { 375 var jobList = (IEnumerable<RefreshableJob>)jobs; 376 foreach (var job in jobList) { 377 progress.Status = "Pausing job \"" + job.Job.Name + "\"..."; 378 HiveAdminClient.PauseJob(job); 379 } 380 } 381 382 private void StopJobsAsync(object jobs) { 383 var jobList = (IEnumerable<RefreshableJob>) jobs; 384 foreach (var job in jobList) { 385 progress.Status = "Stopping job \"" + job.Job.Name + "\"..."; 386 HiveAdminClient.StopJob(job); 387 } 388 } 389 390 private void RemoveJobsAsync(object jobs) { 391 var jobList = (IEnumerable<RefreshableJob>)jobs; 392 progress.Start(); 393 foreach (var job in jobList) { 394 progress.Status = "Removing job \"" + job.Job.Name + "\"..."; 395 HiveAdminClient.RemoveJob(job); 396 } 397 progress.Finish(); 209 398 } 210 399
Note: See TracChangeset
for help on using the changeset viewer.