Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Hive.Server.Console/3.2/AddJobForm.cs @ 2074

Last change on this file since 2074 was 2026, checked in by aleitner, 15 years ago

Drag'n'Drop for changing group (also subgroup) for client (#626)

File size: 5.6 KB
RevLine 
[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
22using System;
[1018]23using System.Collections.Generic;
24using System.ComponentModel;
25using System.Data;
26using System.Drawing;
27using System.Linq;
28using System.Text;
29using System.Windows.Forms;
30using HeuristicLab.Hive.Contracts.Interfaces;
31using HeuristicLab.Hive.Contracts.BusinessObjects;
32using HeuristicLab.Hive.Contracts;
[1120]33using HeuristicLab.Hive.JobBase;
34using HeuristicLab.Core;
[2026]35using System.ServiceModel;
[1018]36
[1089]37namespace 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            }
130            job.SerializedJob = PersistenceManager.SaveToGZip(new TestJob());
131            Response resp = jobManager.AddNewJob(job);
[1018]132          }
[1164]133          if (addJobEvent != null) {
134            addJobEvent();
135          }
[1030]136          this.Close();
137        } else {
138          lblError.Text = "Wrong number of Jobs";
[1018]139        }
[1030]140
[1018]141      }
[1030]142      catch {
143        lblError.Text = "There should be a number";
144      }
[1018]145    }
146
[1037]147    private void BtnClose_Click(object sender, EventArgs e) {
[1018]148      this.Close();
149    }
[1037]150
[1937]151    private void cbAllGroups_CheckedChanged(object sender, EventArgs e) {
152      foreach (Control control in gbGroups.Controls) {
153        control.Enabled = !cbAllGroups.Checked;
154      }
155    }
[1037]156
[1956]157    private void btnAddGroup_Click(object sender, EventArgs e) {
158      AddGroup();
159    }
[1937]160
[1956]161    private void btnRemoveGroup_Click(object sender, EventArgs e) {
162      RemoveGroup();
163    }
164
165    private void lbGroupsOut_SelectedIndexChanged(object sender, EventArgs e) {
166      AddGroup();
167    }
168
169    private void lbGroupsIn_SelectedIndexChanged(object sender, EventArgs e) {
170      RemoveGroup();
171    }
172
173    private void AddGroup() {
174      if (lbGroupsOut.SelectedItem != null) {
175        lbGroupsIn.Items.Add(lbGroupsOut.SelectedItem);
176        lbGroupsOut.Items.RemoveAt(lbGroupsOut.SelectedIndex);
177      }
178 
179    }
180
181    private void RemoveGroup() {
182      if (lbGroupsIn.SelectedItem != null) {
183        lbGroupsOut.Items.Add(lbGroupsIn.SelectedItem);
184        lbGroupsIn.Items.RemoveAt(lbGroupsIn.SelectedIndex);
185      }
186    }
187
188    private void btnLoad_Click(object sender, EventArgs e) {
189
190    }
191
192
[1018]193  }
194}
Note: See TracBrowser for help on using the repository browser.