[1030] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
| 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;
|
---|
[1018] | 23 | using System.Collections.Generic;
|
---|
| 24 | using System.ComponentModel;
|
---|
| 25 | using System.Data;
|
---|
| 26 | using System.Drawing;
|
---|
| 27 | using System.Linq;
|
---|
| 28 | using System.Text;
|
---|
| 29 | using System.Windows.Forms;
|
---|
| 30 | using HeuristicLab.Hive.Contracts.Interfaces;
|
---|
| 31 | using HeuristicLab.Hive.Contracts.BusinessObjects;
|
---|
| 32 | using HeuristicLab.Hive.Contracts;
|
---|
[1120] | 33 | using HeuristicLab.Hive.JobBase;
|
---|
| 34 | using HeuristicLab.Core;
|
---|
[2026] | 35 | using System.ServiceModel;
|
---|
[1018] | 36 |
|
---|
[1089] | 37 | namespace HeuristicLab.Hive.Server.ServerConsole {
|
---|
[1164] | 38 |
|
---|
| 39 | public delegate void addDelegate();
|
---|
| 40 |
|
---|
[1018] | 41 | public partial class AddJobForm : Form {
|
---|
| 42 |
|
---|
[1164] | 43 | public event addDelegate addJobEvent;
|
---|
| 44 |
|
---|
[1937] | 45 | ResponseList<Project> projects = null;
|
---|
[1018] | 46 | IJobManager jobManager;
|
---|
[1937] | 47 | IClientManager clientManager;
|
---|
| 48 | ResponseList<ClientGroup> clientGroups;
|
---|
[1018] | 49 |
|
---|
[1937] | 50 | Dictionary<Guid, string> clients = null;
|
---|
| 51 |
|
---|
[1018] | 52 | public AddJobForm() {
|
---|
| 53 | InitializeComponent();
|
---|
[1937] | 54 |
|
---|
| 55 | clients = new Dictionary<Guid, string>();
|
---|
[1037] | 56 | AddJob();
|
---|
[1937] | 57 |
|
---|
[1018] | 58 | }
|
---|
| 59 |
|
---|
[1037] | 60 | private void AddJob() {
|
---|
[2026] | 61 | try {
|
---|
| 62 |
|
---|
[1018] | 63 | jobManager =
|
---|
| 64 | ServiceLocator.GetJobManager();
|
---|
[1937] | 65 | projects = jobManager.GetAllProjects();
|
---|
[1956] | 66 | clientManager =
|
---|
| 67 | ServiceLocator.GetClientManager();
|
---|
| 68 | clientGroups = clientManager.GetAllClientGroups();
|
---|
[1937] | 69 | cbProject.Items.Add("none");
|
---|
| 70 | cbProject.SelectedIndex = 0;
|
---|
| 71 | foreach (Project project in projects.List) {
|
---|
| 72 | cbProject.Items.Add(project.Name);
|
---|
[1018] | 73 | }
|
---|
[1937] | 74 |
|
---|
[1956] | 75 | AddClientGroups();
|
---|
[1937] | 76 |
|
---|
[1956] | 77 | foreach (KeyValuePair<Guid, string> kvp in clients) {
|
---|
| 78 | lbGroupsOut.Items.Add(kvp.Value + " (" + kvp.Key + ")");
|
---|
| 79 | }
|
---|
[2026] | 80 | }
|
---|
| 81 | catch (FaultException fe) {
|
---|
| 82 | MessageBox.Show(fe.Message);
|
---|
| 83 | }
|
---|
[1956] | 84 |
|
---|
[1018] | 85 | }
|
---|
| 86 |
|
---|
[1937] | 87 | private void AddClientGroups() {
|
---|
| 88 | foreach (ClientGroup cg in clientGroups.List) {
|
---|
[1956] | 89 | if (cg.Id != Guid.Empty)
|
---|
[1937] | 90 | clients.Add(cg.Id, cg.Name);
|
---|
| 91 | AddClientOrGroup(cg);
|
---|
| 92 | }
|
---|
| 93 | }
|
---|
| 94 |
|
---|
| 95 | private void AddClientOrGroup(ClientGroup clientGroup) {
|
---|
| 96 | foreach (Resource resource in clientGroup.Resources) {
|
---|
| 97 | if (resource is ClientGroup) {
|
---|
[1956] | 98 | if (resource.Id != Guid.Empty)
|
---|
[1937] | 99 | clients.Add(resource.Id, resource.Name);
|
---|
| 100 | AddClientOrGroup(resource as ClientGroup);
|
---|
| 101 | }
|
---|
| 102 | }
|
---|
| 103 |
|
---|
| 104 | }
|
---|
| 105 |
|
---|
[1037] | 106 | private void BtnAdd_Click(object sender, EventArgs e) {
|
---|
[1030] | 107 | try {
|
---|
| 108 | lblError.Text = "";
|
---|
| 109 | int numJobs = Convert.ToInt32(tbNumJobs.Text);
|
---|
| 110 | if (numJobs > 0) {
|
---|
| 111 | for (int i = 0; i < numJobs; i++) {
|
---|
[1956] | 112 | Job job = new Job { State = State.offline, CoresNeeded = 1 };
|
---|
| 113 |
|
---|
| 114 | // if project selected (0 -> none)
|
---|
[1937] | 115 | if (cbProject.SelectedIndex != 0) {
|
---|
[1956] | 116 | job.Project = projects.List[cbProject.SelectedIndex - 1];
|
---|
[1030] | 117 | }
|
---|
[1956] | 118 |
|
---|
| 119 | if (!cbAllGroups.Checked) {
|
---|
| 120 | List<Guid> groupsToCalculate = new List<Guid>();
|
---|
| 121 | foreach (string item in lbGroupsIn.Items) {
|
---|
| 122 | int start = item.IndexOf("(");
|
---|
| 123 | int end = item.IndexOf(")");
|
---|
| 124 | string substring = item.Substring(start + 1, end - start - 1);
|
---|
| 125 | Guid guid = new Guid(substring);
|
---|
| 126 | groupsToCalculate.Add(guid);
|
---|
| 127 | }
|
---|
| 128 | job.AssignedResourceIds = groupsToCalculate;
|
---|
| 129 | }
|
---|
[2082] | 130 |
|
---|
| 131 | ComputableJob computableJob =
|
---|
| 132 | new ComputableJob();
|
---|
| 133 | computableJob.JobInfo = job;
|
---|
| 134 | computableJob.SerializedJob = PersistenceManager.SaveToGZip(new TestJob());
|
---|
| 135 | Response resp = jobManager.AddNewJob(computableJob);
|
---|
[1018] | 136 | }
|
---|
[1164] | 137 | if (addJobEvent != null) {
|
---|
| 138 | addJobEvent();
|
---|
| 139 | }
|
---|
[1030] | 140 | this.Close();
|
---|
| 141 | } else {
|
---|
| 142 | lblError.Text = "Wrong number of Jobs";
|
---|
[1018] | 143 | }
|
---|
[1030] | 144 |
|
---|
[1018] | 145 | }
|
---|
[1030] | 146 | catch {
|
---|
| 147 | lblError.Text = "There should be a number";
|
---|
| 148 | }
|
---|
[1018] | 149 | }
|
---|
| 150 |
|
---|
[1037] | 151 | private void BtnClose_Click(object sender, EventArgs e) {
|
---|
[1018] | 152 | this.Close();
|
---|
| 153 | }
|
---|
[1037] | 154 |
|
---|
[1937] | 155 | private void cbAllGroups_CheckedChanged(object sender, EventArgs e) {
|
---|
| 156 | foreach (Control control in gbGroups.Controls) {
|
---|
| 157 | control.Enabled = !cbAllGroups.Checked;
|
---|
| 158 | }
|
---|
| 159 | }
|
---|
[1037] | 160 |
|
---|
[1956] | 161 | private void btnAddGroup_Click(object sender, EventArgs e) {
|
---|
| 162 | AddGroup();
|
---|
| 163 | }
|
---|
[1937] | 164 |
|
---|
[1956] | 165 | private void btnRemoveGroup_Click(object sender, EventArgs e) {
|
---|
| 166 | RemoveGroup();
|
---|
| 167 | }
|
---|
| 168 |
|
---|
| 169 | private void lbGroupsOut_SelectedIndexChanged(object sender, EventArgs e) {
|
---|
| 170 | AddGroup();
|
---|
| 171 | }
|
---|
| 172 |
|
---|
| 173 | private void lbGroupsIn_SelectedIndexChanged(object sender, EventArgs e) {
|
---|
| 174 | RemoveGroup();
|
---|
| 175 | }
|
---|
| 176 |
|
---|
| 177 | private void AddGroup() {
|
---|
| 178 | if (lbGroupsOut.SelectedItem != null) {
|
---|
| 179 | lbGroupsIn.Items.Add(lbGroupsOut.SelectedItem);
|
---|
| 180 | lbGroupsOut.Items.RemoveAt(lbGroupsOut.SelectedIndex);
|
---|
| 181 | }
|
---|
| 182 |
|
---|
| 183 | }
|
---|
| 184 |
|
---|
| 185 | private void RemoveGroup() {
|
---|
| 186 | if (lbGroupsIn.SelectedItem != null) {
|
---|
| 187 | lbGroupsOut.Items.Add(lbGroupsIn.SelectedItem);
|
---|
| 188 | lbGroupsIn.Items.RemoveAt(lbGroupsIn.SelectedIndex);
|
---|
| 189 | }
|
---|
| 190 | }
|
---|
| 191 |
|
---|
| 192 | private void btnLoad_Click(object sender, EventArgs e) {
|
---|
| 193 |
|
---|
| 194 | }
|
---|
| 195 |
|
---|
| 196 |
|
---|
[1018] | 197 | }
|
---|
| 198 | }
|
---|