Free cookie consent management tool by TermsFeed Policy Generator

Changeset 7156


Ignore:
Timestamp:
12/08/11 18:53:41 (13 years ago)
Author:
ascheibe
Message:

#1672 fixed starting, pausing and stopping of jobs and tasks

Location:
trunk/sources
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Clients.Hive.JobManager/3.3/Views/RefreshableHiveJobView.cs

    r7068 r7156  
    3232using HeuristicLab.Optimization;
    3333using HeuristicLab.PluginInfrastructure;
     34using System.Threading.Tasks;
    3435
    3536namespace HeuristicLab.Clients.Hive.JobManager.Views {
     
    316317        SetEnabledStateOfControls();
    317318      }
    318     }
    319 
     319    }
    320320
    321321    private void UpdateStateLogList() {
     
    336336      if (nameTextBox.Text.Trim() == string.Empty) {
    337337        MessageBox.Show("Please enter a name for the job before uploading it!", "HeuristicLab Hive Job Manager", MessageBoxButtons.OK, MessageBoxIcon.Information);
     338      } else if (Content.ExecutionState == ExecutionState.Paused) {             
     339        var task = System.Threading.Tasks.Task.Factory.StartNew(ResumeJobAsync, Content);
     340        task.ContinueWith((t) => {
     341          FinishProgressView();
     342          MessageBox.Show("An error occured resuming the job. See the log for more information.", "HeuristicLab Hive Job Manager", MessageBoxButtons.OK, MessageBoxIcon.Error);
     343          Content.Log.LogException(t.Exception);
     344        }, TaskContinuationOptions.OnlyOnFaulted);
    338345      } else {
    339346        HiveClient.StartJob((Exception ex) => ErrorHandling.ShowErrorDialog(this, "Start failed.", ex), Content, new CancellationToken());
    340347      }
    341348    }
     349
    342350    private void pauseButton_Click(object sender, EventArgs e) {
    343       HiveClient.PauseJob(Content);
    344     }
     351      var task = System.Threading.Tasks.Task.Factory.StartNew(PauseJobAsync, Content);
     352      task.ContinueWith((t) => {       
     353        FinishProgressView();
     354        MessageBox.Show("An error occured pausing the job. See the log for more information.", "HeuristicLab Hive Job Manager", MessageBoxButtons.OK, MessageBoxIcon.Error);
     355        Content.Log.LogException(t.Exception);
     356      }, TaskContinuationOptions.OnlyOnFaulted);
     357    }         
     358
    345359    private void stopButton_Click(object sender, EventArgs e) {
    346       HiveClient.StopJob(Content);
     360      var task = System.Threading.Tasks.Task.Factory.StartNew(StopJobAsync, Content);
     361      task.ContinueWith((t) => {
     362        FinishProgressView();
     363        MessageBox.Show("An error occured stopping the job. See the log for more information.", "HeuristicLab Hive Job Manager", MessageBoxButtons.OK, MessageBoxIcon.Error);
     364        Content.Log.LogException(t.Exception);
     365      }, TaskContinuationOptions.OnlyOnFaulted);
    347366    }
    348367    private void resetButton_Click(object sender, EventArgs e) { }
     368
     369    private void PauseJobAsync(object job) {
     370      IProgress prog = new Progress();
     371      prog.Status = "Pausing job...";
     372      SetProgressView(prog);
     373      HiveClient.PauseJob((RefreshableJob)job);
     374      FinishProgressView();
     375    }
     376
     377    private void StopJobAsync(object job) {
     378      IProgress prog = new Progress();
     379      prog.Status = "Stopping job...";
     380      SetProgressView(prog);
     381      HiveClient.StopJob((RefreshableJob)job);
     382      FinishProgressView();
     383    }
     384
     385    private void ResumeJobAsync(object job) {
     386      IProgress prog = new Progress();
     387      prog.Status = "Resuming job...";
     388      SetProgressView(prog);
     389      HiveClient.ResumeJob((RefreshableJob)job);
     390      FinishProgressView();
     391    }
    349392
    350393    private void nameTextBox_Validated(object sender, EventArgs e) {
     
    385428      }
    386429    }
    387 
    388 
    389430    #endregion
    390431
     
    394435        startButton.Enabled = pauseButton.Enabled = stopButton.Enabled = resetButton.Enabled = false;
    395436      } else {
    396         startButton.Enabled = Content.IsControllable && Content.HiveTasks != null && Content.HiveTasks.Count > 0 && Content.ExecutionState == ExecutionState.Prepared;
     437        startButton.Enabled = Content.IsControllable && Content.HiveTasks != null && Content.HiveTasks.Count > 0 && (Content.ExecutionState == ExecutionState.Prepared || Content.ExecutionState == ExecutionState.Paused);
    397438        pauseButton.Enabled = Content.IsControllable && Content.ExecutionState == ExecutionState.Started;
    398439        stopButton.Enabled = Content.IsControllable && Content.ExecutionState == ExecutionState.Started;
     
    416457
    417458    private void SetProgressView() {
    418       if (progressView == null) {
    419         progressView = new ProgressView(this, Content.Progress);
    420       }
    421       progressView.Progress = Content.Progress;
     459      if (InvokeRequired) {
     460        Invoke(new Action(SetProgressView));
     461      } else {
     462        if (progressView == null) {
     463          progressView = new ProgressView(this, Content.Progress);
     464        } else {
     465          progressView.Progress = Content.Progress;
     466        }
     467      }
     468    }
     469
     470    private void SetProgressView(IProgress progress) {
     471      if (InvokeRequired) {
     472        Invoke(new Action<IProgress>(SetProgressView), progress);
     473      } else {
     474        if (progressView == null) {
     475          progressView = new ProgressView(this, progress);
     476        } else {
     477          progressView.Progress = progress;
     478        }
     479      }
    422480    }
    423481
    424482    private void FinishProgressView() {
    425       if (progressView != null) {
    426         progressView.Finish();
    427         progressView = null;
    428         SetEnabledStateOfControls();
     483      if (InvokeRequired) {
     484        Invoke(new Action(FinishProgressView));
     485      } else {
     486        if (progressView != null) {
     487          progressView.Finish();
     488          progressView = null;
     489          SetEnabledStateOfControls();
     490        }
    429491      }
    430492    }
  • trunk/sources/HeuristicLab.Clients.Hive.Views/3.3/HiveTasks/OptimizerHiveTaskView.cs

    r6976 r7156  
    2323using System.Windows.Forms;
    2424using HeuristicLab.MainForm;
     25using System.Threading.Tasks;
     26using HeuristicLab.PluginInfrastructure;
    2527
    2628namespace HeuristicLab.Clients.Hive.Views {
     
    2830  [Content(typeof(OptimizerHiveTask), true)]
    2931  public partial class OptimizerHiveTaskView : HiveTaskView {
     32    private ProgressView progressView;
     33
    3034    public new OptimizerHiveTask Content {
    3135      get { return (OptimizerHiveTask)base.Content; }
     
    6771    #region Child Control Events
    6872    private void restartButton_Click(object sender, EventArgs e) {
    69       Content.Restart();
     73      var task = System.Threading.Tasks.Task.Factory.StartNew(ResumeTaskAsync);
     74      task.ContinueWith((t) => {
     75        FinishProgressView();
     76        ErrorHandling.ShowErrorDialog(this, "An error occured while resuming the task.", t.Exception);
     77      }, TaskContinuationOptions.OnlyOnFaulted);
    7078    }
    7179
    7280    private void pauseButton_Click(object sender, EventArgs e) {
    73       Content.Pause();
     81      var task = System.Threading.Tasks.Task.Factory.StartNew(PauseTaskAsync);
     82      task.ContinueWith((t) => {
     83        FinishProgressView();
     84        ErrorHandling.ShowErrorDialog(this, "An error occured while pausing the task.", t.Exception);
     85      }, TaskContinuationOptions.OnlyOnFaulted);
    7486    }
    7587
    7688    private void stopButton_Click(object sender, EventArgs e) {
    77       Content.Stop();
     89      var task = System.Threading.Tasks.Task.Factory.StartNew(StopTaskAsync);
     90      task.ContinueWith((t) => {
     91        FinishProgressView();
     92        ErrorHandling.ShowErrorDialog(this, "An error occured while stopping the task.", t.Exception);
     93      }, TaskContinuationOptions.OnlyOnFaulted);
    7894    }
    7995    #endregion
     96
     97    private void PauseTaskAsync() {
     98      IProgress prog = new Progress();
     99      prog.Status = "Pausing task. Please be patient for the command to take effect.";
     100      SetProgressView(prog);
     101      Content.Pause();
     102      FinishProgressView();
     103    }
     104
     105    private void StopTaskAsync() {
     106      IProgress prog = new Progress();
     107      prog.Status = "Stopping task. Please be patient for the command to take effect.";
     108      SetProgressView(prog);
     109      Content.Stop();
     110      FinishProgressView();
     111    }
     112
     113    private void ResumeTaskAsync() {
     114      IProgress prog = new Progress();
     115      prog.Status = "Resuming task. Please be patient for the command to take effect.";
     116      SetProgressView(prog);
     117      Content.Restart();
     118      FinishProgressView();
     119    }
     120
     121    private void SetProgressView(IProgress progress) {
     122      if (InvokeRequired) {
     123        Invoke(new Action<IProgress>(SetProgressView), progress);
     124      } else {
     125        if (progressView == null) {
     126          progressView = new ProgressView(this, progress);
     127        } else {
     128          progressView.Progress = progress;
     129        }
     130      }
     131    }
     132
     133    private void FinishProgressView() {
     134      if (InvokeRequired) {
     135        Invoke(new Action(FinishProgressView));
     136      } else {
     137        if (progressView != null) {
     138          progressView.Finish();
     139          progressView = null;
     140          SetEnabledStateOfControls();
     141        }
     142      }
     143    }
    80144
    81145    protected override void SetEnabledStateOfControls() {
  • trunk/sources/HeuristicLab.Clients.Hive/3.3/HiveClient.cs

    r7144 r7156  
    236236        }
    237237      });
    238       // execution state does not need to be set. it will be set to Stopped, when all jobs have been downloaded
     238      refreshableJob.ExecutionState = ExecutionState.Stopped;
     239    }
     240
     241    public static void ResumeJob(RefreshableJob refreshableJob) {
     242      HiveServiceLocator.Instance.CallHiveService(service => {
     243        foreach (HiveTask task in refreshableJob.GetAllHiveTasks()) {
     244          if (task.Task.State == TaskState.Paused) {           
     245            service.RestartTask(task.Task.Id);           
     246          }
     247        }
     248      });
     249      refreshableJob.ExecutionState = ExecutionState.Started;
    239250    }
    240251
Note: See TracChangeset for help on using the changeset viewer.