Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Server.Console/3.3/AddJobForm.cs @ 4253

Last change on this file since 4253 was 4253, checked in by cneumuel, 14 years ago

Rename "Client" to "Slave" #1157

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