Free cookie consent management tool by TermsFeed Policy Generator

source: branches/Operator Architecture Refactoring/HeuristicLab.Hive.Server.Console/3.2/AddJobForm.cs @ 2006

Last change on this file since 2006 was 1956, checked in by aleitner, 16 years ago

Adding job with project and groups
new project can be created
(#626)

File size: 5.5 KB
Line 
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;
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;
33using HeuristicLab.Hive.JobBase;
34using HeuristicLab.Core;
35
36namespace HeuristicLab.Hive.Server.ServerConsole {
37
38  public delegate void addDelegate();
39
40  public partial class AddJobForm : Form {
41
42    public event addDelegate addJobEvent;
43
44    ResponseList<Project> projects = null;
45    IJobManager jobManager;
46    IClientManager clientManager;
47    ResponseList<ClientGroup> clientGroups;
48
49    Dictionary<Guid, string> clients = null;
50
51    public AddJobForm() {
52      InitializeComponent();
53
54      clients = new Dictionary<Guid, string>();
55      AddJob();
56
57    }
58
59    private void AddJob() {
60      jobManager =
61        ServiceLocator.GetJobManager();
62      projects = jobManager.GetAllProjects();
63      clientManager =
64        ServiceLocator.GetClientManager();
65      clientGroups = clientManager.GetAllClientGroups();
66      cbProject.Items.Add("none");
67      cbProject.SelectedIndex = 0;
68      foreach (Project project in projects.List) {
69        cbProject.Items.Add(project.Name);
70      }
71
72      AddClientGroups();
73
74      foreach (KeyValuePair<Guid, string> kvp in clients) {
75        lbGroupsOut.Items.Add(kvp.Value + " (" + kvp.Key + ")");
76      }
77
78    }
79
80    private void AddClientGroups() {
81     foreach (ClientGroup cg in clientGroups.List) {
82       if (cg.Id != Guid.Empty)
83       clients.Add(cg.Id, cg.Name);
84        AddClientOrGroup(cg);
85      }
86    }
87
88    private void AddClientOrGroup(ClientGroup clientGroup) {
89      foreach (Resource resource in clientGroup.Resources) {
90        if (resource is ClientGroup) {
91          if (resource.Id != Guid.Empty)
92          clients.Add(resource.Id, resource.Name);
93          AddClientOrGroup(resource as ClientGroup);
94        }
95      }
96   
97    }
98
99    private void BtnAdd_Click(object sender, EventArgs e) {
100      try {
101        lblError.Text = "";
102        int numJobs = Convert.ToInt32(tbNumJobs.Text);
103        if (numJobs > 0) {
104          for (int i = 0; i < numJobs; i++) {
105            Job job = new Job { State = State.offline, CoresNeeded = 1 };
106           
107            // if project selected (0 -> none)
108            if (cbProject.SelectedIndex != 0) {
109              job.Project = projects.List[cbProject.SelectedIndex - 1];
110            }
111
112            if (!cbAllGroups.Checked) {
113              List<Guid> groupsToCalculate = new List<Guid>();
114              foreach (string item in lbGroupsIn.Items) {
115                int start = item.IndexOf("(");
116                int end = item.IndexOf(")");
117                string substring = item.Substring(start + 1, end - start - 1);
118                Guid guid = new Guid(substring);
119                groupsToCalculate.Add(guid);
120              }
121              job.AssignedResourceIds = groupsToCalculate;
122            }
123            job.SerializedJob = PersistenceManager.SaveToGZip(new TestJob());
124            Response resp = jobManager.AddNewJob(job);
125          }
126          if (addJobEvent != null) {
127            addJobEvent();
128          }
129          this.Close();
130        } else {
131          lblError.Text = "Wrong number of Jobs";
132        }
133
134      }
135      catch {
136        lblError.Text = "There should be a number";
137      }
138    }
139
140    private void BtnClose_Click(object sender, EventArgs e) {
141      this.Close();
142    }
143
144    private void cbAllGroups_CheckedChanged(object sender, EventArgs e) {
145      foreach (Control control in gbGroups.Controls) {
146        control.Enabled = !cbAllGroups.Checked;
147      }
148    }
149
150    private void btnAddGroup_Click(object sender, EventArgs e) {
151      AddGroup();
152    }
153
154    private void btnRemoveGroup_Click(object sender, EventArgs e) {
155      RemoveGroup();
156    }
157
158    private void lbGroupsOut_SelectedIndexChanged(object sender, EventArgs e) {
159      AddGroup();
160    }
161
162    private void lbGroupsIn_SelectedIndexChanged(object sender, EventArgs e) {
163      RemoveGroup();
164    }
165
166    private void AddGroup() {
167      if (lbGroupsOut.SelectedItem != null) {
168        lbGroupsIn.Items.Add(lbGroupsOut.SelectedItem);
169        lbGroupsOut.Items.RemoveAt(lbGroupsOut.SelectedIndex);
170      }
171 
172    }
173
174    private void RemoveGroup() {
175      if (lbGroupsIn.SelectedItem != null) {
176        lbGroupsOut.Items.Add(lbGroupsIn.SelectedItem);
177        lbGroupsIn.Items.RemoveAt(lbGroupsIn.SelectedIndex);
178      }
179    }
180
181    private void btnLoad_Click(object sender, EventArgs e) {
182
183    }
184
185
186  }
187}
Note: See TracBrowser for help on using the repository browser.