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 @ 4302

Last change on this file since 4302 was 4302, checked in by cneumuel, 14 years ago
  • made ServerConsole work with wsHttpBinding
  • applied role-base restrictions to all WCF-Services
  • made wcf-services work with certificates
  • renamed ExecutionEngineFacade to ClientFacade

(#1168)

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