[10150] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[11171] | 3 | * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[10150] | 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.Collections.Generic;
|
---|
| 24 | using System.Threading;
|
---|
| 25 | using HeuristicLab.Core;
|
---|
| 26 | using HeuristicLab.MainForm;
|
---|
| 27 | using HeuristicLab.Optimization;
|
---|
[10170] | 28 | using HeuristicLab.Optimizer;
|
---|
[10150] | 29 | using HeuristicLab.PluginInfrastructure;
|
---|
| 30 |
|
---|
[10170] | 31 | namespace HeuristicLab.Clients.Hive.JobManager {
|
---|
[10150] | 32 | public class RunInHiveMenuItem : HeuristicLab.MainForm.WindowsForms.MenuItem, IOptimizerUserInterfaceItemProvider {
|
---|
| 33 | public override string Name {
|
---|
| 34 | get { return "&Run In Hive"; }
|
---|
| 35 | }
|
---|
| 36 | public override IEnumerable<string> Structure {
|
---|
| 37 | get { return new string[] { "&Services", "&Hive" }; }
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 | public override int Position {
|
---|
| 41 | get { return 10002; }
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | protected override void OnActiveViewChanged(object sender, EventArgs e) {
|
---|
| 45 | IContentView activeView = MainFormManager.MainForm.ActiveView as IContentView;
|
---|
| 46 |
|
---|
| 47 | if (activeView != null && activeView.Content != null && !activeView.Locked) {
|
---|
| 48 | var content = activeView.Content as IItem;
|
---|
| 49 | if (content != null) {
|
---|
| 50 | Type contentType = content.GetType();
|
---|
| 51 | ToolStripItem.Enabled = ItemTask.IsTypeSupported(contentType);
|
---|
[11079] | 52 | return;
|
---|
[10150] | 53 | }
|
---|
| 54 | }
|
---|
[11079] | 55 | ToolStripItem.Enabled = false;
|
---|
[10150] | 56 | }
|
---|
| 57 |
|
---|
| 58 | private IProgress progress;
|
---|
| 59 | private IItem content;
|
---|
| 60 | public override void Execute() {
|
---|
| 61 | IContentView activeView = MainFormManager.MainForm.ActiveView as IContentView;
|
---|
| 62 | content = activeView.Content as IItem;
|
---|
| 63 |
|
---|
| 64 | //IOptimizer and IExecutables need some special care
|
---|
| 65 | if (content is IOptimizer) {
|
---|
| 66 | ((IOptimizer)content).Runs.Clear();
|
---|
| 67 | }
|
---|
| 68 | if (content is IExecutable) {
|
---|
| 69 | IExecutable exec = content as IExecutable;
|
---|
| 70 | if (exec.ExecutionState != ExecutionState.Prepared) {
|
---|
| 71 | exec.Prepare();
|
---|
| 72 | }
|
---|
| 73 | }
|
---|
| 74 |
|
---|
| 75 | HiveClient.Instance.Refresh();
|
---|
| 76 |
|
---|
| 77 | ItemTask hiveTask = ItemTask.GetItemTaskForItem(content);
|
---|
| 78 | HiveTask task = hiveTask.CreateHiveTask();
|
---|
| 79 | RefreshableJob rJob = new RefreshableJob();
|
---|
[10170] | 80 | rJob.Job.Name = content.ToString();
|
---|
[10150] | 81 | rJob.HiveTasks.Add(task);
|
---|
| 82 | task.ItemTask.ComputeInParallel = content is Experiment || content is BatchRun;
|
---|
| 83 |
|
---|
| 84 | progress = MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().AddOperationProgressToContent(this.content, "Uploading to Hive...");
|
---|
| 85 | rJob.Progress = progress;
|
---|
| 86 | progress.ProgressStateChanged += progress_ProgressStateChanged;
|
---|
| 87 |
|
---|
| 88 | HiveClient.StartJob(new Action<Exception>(HandleEx), rJob, new CancellationToken());
|
---|
| 89 | }
|
---|
| 90 |
|
---|
| 91 | private void progress_ProgressStateChanged(object sender, EventArgs e) {
|
---|
| 92 | if (progress.ProgressState != ProgressState.Started) {
|
---|
| 93 | MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromContent(content);
|
---|
| 94 | progress.ProgressStateChanged -= progress_ProgressStateChanged;
|
---|
| 95 | }
|
---|
| 96 | }
|
---|
| 97 |
|
---|
| 98 | private void HandleEx(Exception ex) {
|
---|
| 99 | MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromContent(content);
|
---|
| 100 | progress.ProgressStateChanged -= progress_ProgressStateChanged;
|
---|
| 101 | ErrorHandling.ShowErrorDialog("Error uploading tasks", ex);
|
---|
| 102 | }
|
---|
| 103 | }
|
---|
| 104 | }
|
---|