[794] | 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;
|
---|
| 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;
|
---|
[831] | 30 | using HeuristicLab.Hive.Contracts.Interfaces;
|
---|
| 31 | using HeuristicLab.Hive.Contracts.BusinessObjects;
|
---|
[904] | 32 | using HeuristicLab.Hive.Contracts;
|
---|
[1753] | 33 | using System.Threading;
|
---|
[2026] | 34 | using System.ServiceModel;
|
---|
[794] | 35 |
|
---|
[1089] | 36 | namespace HeuristicLab.Hive.Server.ServerConsole {
|
---|
[794] | 37 |
|
---|
[1645] | 38 | /// <summary>
|
---|
| 39 | /// if form is closed the loginform gets an information
|
---|
| 40 | /// </summary>
|
---|
| 41 | /// <param name="cf"></param>
|
---|
| 42 | /// <param name="error"></param>
|
---|
[1030] | 43 | public delegate void closeForm(bool cf, bool error);
|
---|
[794] | 44 |
|
---|
| 45 | public partial class HiveServerManagementConsole : Form {
|
---|
| 46 |
|
---|
| 47 | public event closeForm closeFormEvent;
|
---|
| 48 |
|
---|
[1136] | 49 | #region private variables
|
---|
| 50 | private ResponseList<Job> jobs = null;
|
---|
[844] | 51 |
|
---|
[1937] | 52 | List<ListViewGroup> jobGroup;
|
---|
| 53 | private Dictionary<Guid, List<ListViewItem>> clientList = new Dictionary<Guid, List<ListViewItem>>();
|
---|
| 54 | private List<Changes> changes = new List<Changes>();
|
---|
[1261] | 55 |
|
---|
[1136] | 56 | private Job currentJob = null;
|
---|
| 57 | private ClientInfo currentClient = null;
|
---|
[1832] | 58 |
|
---|
[2007] | 59 | private TreeNode currentGroupNode = null;
|
---|
[1937] | 60 | Guid parentgroup = Guid.Empty;
|
---|
[1136] | 61 | private ToolTip tt = new ToolTip();
|
---|
[1645] | 62 |
|
---|
[1657] | 63 | private const string NOGROUP = "No group";
|
---|
[2118] | 64 | private TreeNode hoverNode;
|
---|
| 65 | private List<ListViewGroup> lvClientGroups;
|
---|
[1937] | 66 | #endregion
|
---|
| 67 |
|
---|
| 68 | #region Properties
|
---|
[1645] | 69 | private IClientManager ClientManager {
|
---|
| 70 | get {
|
---|
[2026] | 71 | try {
|
---|
| 72 | return ServiceLocator.GetClientManager();
|
---|
| 73 | }
|
---|
| 74 | catch (FaultException ex) {
|
---|
| 75 | MessageBox.Show(ex.Message);
|
---|
| 76 | }
|
---|
| 77 | return null;
|
---|
[1645] | 78 | }
|
---|
| 79 | }
|
---|
[1136] | 80 | #endregion
|
---|
| 81 |
|
---|
[794] | 82 | public HiveServerManagementConsole() {
|
---|
| 83 | InitializeComponent();
|
---|
[1598] | 84 | Init();
|
---|
[1037] | 85 | AddClients();
|
---|
| 86 | AddJobs();
|
---|
[1018] | 87 | timerSyncronize.Start();
|
---|
[844] | 88 | }
|
---|
[831] | 89 |
|
---|
[1598] | 90 | private void Init() {
|
---|
| 91 | //adding context menu items for jobs
|
---|
| 92 | menuItemAbortJob.Click += (s, e) => {
|
---|
| 93 | IJobManager jobManager = ServiceLocator.GetJobManager();
|
---|
| 94 | if (lvJobControl.SelectedItems.Count == 1) {
|
---|
[1645] | 95 | jobManager.AbortJob(((Job)(lvJobControl.SelectedItems[0].Tag)).Id);
|
---|
[1598] | 96 | }
|
---|
| 97 | };
|
---|
| 98 |
|
---|
[1645] | 99 | //adding context menu items for jobs
|
---|
[1598] | 100 | menuItemGetSnapshot.Click += (s, e) => {
|
---|
| 101 | IJobManager jobManager = ServiceLocator.GetJobManager();
|
---|
| 102 | if (lvJobControl.SelectedItems.Count == 1) {
|
---|
[1645] | 103 | jobManager.RequestSnapshot(((Job)(lvJobControl.SelectedItems[0].Tag)).Id);
|
---|
[1598] | 104 | }
|
---|
| 105 | };
|
---|
| 106 |
|
---|
[1832] | 107 | //adding group
|
---|
| 108 | menuItemAddGroup.Click += (s, e) => {
|
---|
| 109 | AddGroup addgroup = new AddGroup();
|
---|
| 110 | parentgroup = Guid.Empty;
|
---|
| 111 | if ((tvClientControl.SelectedNode != null) && (((ClientGroup)tvClientControl.SelectedNode.Tag).Id != Guid.Empty)) {
|
---|
| 112 | parentgroup = ((ClientGroup)tvClientControl.SelectedNode.Tag).Id;
|
---|
| 113 | }
|
---|
| 114 | addgroup.addGroupEvent += new AddGroupDelegate(addgroup_addGroupEvent);
|
---|
| 115 | addgroup.Show();
|
---|
| 116 | };
|
---|
| 117 |
|
---|
| 118 | //adding group
|
---|
| 119 | menuItemDeleteGroup.Click += (s, e) => {
|
---|
| 120 | IClientManager clientManager = ServiceLocator.GetClientManager();
|
---|
| 121 | if (tvClientControl.SelectedNode != null) {
|
---|
[2007] | 122 | Response resp = clientManager.DeleteClientGroup(((ClientGroup)tvClientControl.SelectedNode.Tag).Id);
|
---|
| 123 | if (tvClientControl.SelectedNode == currentGroupNode) {
|
---|
| 124 | currentGroupNode = null;
|
---|
| 125 | }
|
---|
| 126 | tvClientControl.Nodes.Remove(tvClientControl.SelectedNode);
|
---|
| 127 | AddClients();
|
---|
[1832] | 128 | }
|
---|
| 129 | };
|
---|
[2007] | 130 |
|
---|
[2118] | 131 | // drag item to treeview
|
---|
[2007] | 132 | lvClientControl.ItemDrag += delegate(object sender, ItemDragEventArgs e) {
|
---|
| 133 | List<string> itemIDs = new List<string>((sender as ListView).SelectedItems.Count);
|
---|
| 134 | foreach (ListViewItem item in (sender as ListView).SelectedItems) {
|
---|
| 135 | itemIDs.Add(item.Name);
|
---|
| 136 | }
|
---|
| 137 | (sender as ListView).DoDragDrop(itemIDs.ToArray(), DragDropEffects.Move);
|
---|
| 138 | };
|
---|
| 139 |
|
---|
[2118] | 140 | // drag enter on treeview
|
---|
[2007] | 141 | tvClientControl.DragEnter += delegate(object sender, DragEventArgs e) {
|
---|
| 142 | e.Effect = DragDropEffects.Move;
|
---|
| 143 | };
|
---|
| 144 |
|
---|
[2118] | 145 | // drag over
|
---|
[2007] | 146 | tvClientControl.DragOver += delegate(object sender, DragEventArgs e) {
|
---|
| 147 | Point mouseLocation = tvClientControl.PointToClient(new Point(e.X, e.Y));
|
---|
| 148 | TreeNode node = tvClientControl.GetNodeAt(mouseLocation);
|
---|
| 149 | if (node != null && ((ClientGroup)node.Tag).Id != Guid.Empty) {
|
---|
| 150 | e.Effect = DragDropEffects.Move;
|
---|
| 151 | if (hoverNode == null) {
|
---|
| 152 | node.BackColor = Color.LightBlue;
|
---|
| 153 | node.ForeColor = Color.White;
|
---|
| 154 | hoverNode = node;
|
---|
| 155 | } else if (hoverNode != node) {
|
---|
| 156 | hoverNode.BackColor = Color.White;
|
---|
| 157 | hoverNode.ForeColor = Color.Black;
|
---|
| 158 | node.BackColor = Color.LightBlue;
|
---|
| 159 | node.ForeColor = Color.White;
|
---|
| 160 | hoverNode = node;
|
---|
| 161 | }
|
---|
| 162 | } else {
|
---|
| 163 | e.Effect = DragDropEffects.None;
|
---|
| 164 | }
|
---|
| 165 | };
|
---|
| 166 |
|
---|
[2118] | 167 | // drag drop event
|
---|
[2007] | 168 | tvClientControl.DragDrop += delegate(object sender, DragEventArgs e) {
|
---|
| 169 | if (e.Data.GetDataPresent(typeof(string[]))) {
|
---|
| 170 | Point dropLocation = (sender as TreeView).PointToClient(new Point(e.X, e.Y));
|
---|
| 171 | TreeNode dropNode = (sender as TreeView).GetNodeAt(dropLocation);
|
---|
| 172 | if (((ClientGroup)dropNode.Tag).Id != Guid.Empty) {
|
---|
[2026] | 173 | Dictionary<ClientInfo, Guid> clients = new Dictionary<ClientInfo, Guid>();
|
---|
[2007] | 174 | foreach (ListViewItem lvi in lvClientControl.SelectedItems) {
|
---|
[2026] | 175 | Guid groupId = Guid.Empty;
|
---|
| 176 | foreach (ListViewGroup lvg in lvClientGroups) {
|
---|
| 177 | if (lvi.Group.Header == ((ClientGroup)lvg.Tag).Name) {
|
---|
| 178 | groupId = ((ClientGroup)lvg.Tag).Id;
|
---|
| 179 | }
|
---|
| 180 | }
|
---|
| 181 | clients.Add((ClientInfo)lvi.Tag, groupId);
|
---|
[2007] | 182 | }
|
---|
| 183 | ChangeGroup(clients, ((ClientGroup)dropNode.Tag).Id);
|
---|
| 184 | }
|
---|
| 185 | tvClientControl_DragLeave(null, EventArgs.Empty);
|
---|
| 186 | AddClients();
|
---|
| 187 | }
|
---|
| 188 | };
|
---|
[1598] | 189 | }
|
---|
| 190 |
|
---|
[2118] | 191 | /// <summary>
|
---|
| 192 | /// Change client to other group
|
---|
| 193 | /// </summary>
|
---|
| 194 | /// <param name="clients">list of clients</param>
|
---|
| 195 | /// <param name="clientgroupID">group of clients</param>
|
---|
[2026] | 196 | private void ChangeGroup(Dictionary<ClientInfo, Guid> clients, Guid clientgroupID) {
|
---|
[2007] | 197 | IClientManager clientManager = ServiceLocator.GetClientManager();
|
---|
[2026] | 198 | foreach (KeyValuePair<ClientInfo, Guid> client in clients) {
|
---|
| 199 | if (client.Key.Id != Guid.Empty) {
|
---|
| 200 | Response resp = clientManager.DeleteResourceFromGroup(client.Value, client.Key.Id);
|
---|
[2007] | 201 | }
|
---|
[2026] | 202 | clientManager.AddResourceToGroup(clientgroupID, client.Key);
|
---|
[2007] | 203 | }
|
---|
| 204 | }
|
---|
| 205 |
|
---|
[1937] | 206 | #region Backgroundworker
|
---|
| 207 | /// <summary>
|
---|
| 208 | /// event on Ticker
|
---|
| 209 | /// </summary>
|
---|
| 210 | /// <param name="obj"></param>
|
---|
| 211 | /// <param name="e"></param>
|
---|
| 212 | private void TickSync(object obj, EventArgs e) {
|
---|
| 213 | if (!updaterWoker.IsBusy) {
|
---|
| 214 | updaterWoker.RunWorkerAsync();
|
---|
| 215 | }
|
---|
| 216 | }
|
---|
[1832] | 217 |
|
---|
[1937] | 218 | private void updaterWoker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) {
|
---|
| 219 | RefreshForm();
|
---|
| 220 | }
|
---|
[1832] | 221 |
|
---|
[1937] | 222 | private void updaterWoker_DoWork(object sender, DoWorkEventArgs e) {
|
---|
| 223 |
|
---|
| 224 | changes.Clear();
|
---|
| 225 |
|
---|
| 226 | ResponseList<Job> jobsOld = jobs;
|
---|
[2026] | 227 | try {
|
---|
| 228 | IJobManager jobManager =
|
---|
| 229 | ServiceLocator.GetJobManager();
|
---|
[1937] | 230 |
|
---|
[2026] | 231 | jobs = jobManager.GetAllJobs();
|
---|
[1937] | 232 |
|
---|
[2026] | 233 | IDictionary<int, Job> jobsOldHelp;
|
---|
| 234 | CloneList(jobsOld, out jobsOldHelp);
|
---|
[1937] | 235 |
|
---|
[2026] | 236 | GetDelta(jobsOld.List, jobsOldHelp);
|
---|
[1937] | 237 |
|
---|
[2026] | 238 | }
|
---|
| 239 | catch (FaultException fe) {
|
---|
| 240 | MessageBox.Show(fe.Message);
|
---|
| 241 | }
|
---|
| 242 |
|
---|
[1832] | 243 | }
|
---|
[2007] | 244 |
|
---|
[1937] | 245 | #endregion
|
---|
[1832] | 246 |
|
---|
[1628] | 247 |
|
---|
[1937] | 248 | /// <summary>
|
---|
[2026] | 249 | /// Adds Exceptionobs to ListView and TreeView
|
---|
[1937] | 250 | /// </summary>
|
---|
| 251 | private void AddJobs() {
|
---|
| 252 | try {
|
---|
| 253 | List<ListViewItem> jobObjects = new List<ListViewItem>();
|
---|
| 254 | IJobManager jobManager =
|
---|
| 255 | ServiceLocator.GetJobManager();
|
---|
| 256 | jobs = jobManager.GetAllJobs();
|
---|
| 257 |
|
---|
| 258 | lvJobControl.Items.Clear();
|
---|
| 259 |
|
---|
| 260 | ListViewGroup lvJobCalculating = new ListViewGroup("calculating", HorizontalAlignment.Left);
|
---|
| 261 | ListViewGroup lvJobFinished = new ListViewGroup("finished", HorizontalAlignment.Left);
|
---|
| 262 | ListViewGroup lvJobPending = new ListViewGroup("pending", HorizontalAlignment.Left);
|
---|
| 263 |
|
---|
| 264 | jobGroup = new List<ListViewGroup>();
|
---|
| 265 | jobGroup.Add(lvJobCalculating);
|
---|
| 266 | jobGroup.Add(lvJobFinished);
|
---|
| 267 | jobGroup.Add(lvJobPending);
|
---|
| 268 |
|
---|
[2109] | 269 | if (jobs != null && jobs.List != null) {
|
---|
[1937] | 270 |
|
---|
[2109] | 271 | foreach (Job job in jobs.List) {
|
---|
| 272 | if (job.State == State.calculating) {
|
---|
| 273 | ListViewItem lvi = new ListViewItem(job.Id.ToString(), 1, lvJobCalculating);
|
---|
| 274 | lvi.Tag = job;
|
---|
| 275 | jobObjects.Add(lvi);
|
---|
| 276 |
|
---|
| 277 | lvi.ToolTipText = (job.Percentage * 100) + "% of job calculated";
|
---|
| 278 | } else if (job.State == State.finished) {
|
---|
| 279 | ListViewItem lvi = new ListViewItem(job.Id.ToString(), 0, lvJobFinished);
|
---|
| 280 | lvi.Tag = job;
|
---|
| 281 | jobObjects.Add(lvi);
|
---|
| 282 | } else if (job.State == State.offline || job.State == State.pending) {
|
---|
| 283 | ListViewItem lvi = new ListViewItem(job.Id.ToString(), 2, lvJobPending);
|
---|
| 284 | lvi.Tag = job;
|
---|
| 285 | jobObjects.Add(lvi);
|
---|
| 286 | }
|
---|
| 287 | } // Jobs
|
---|
| 288 | lvJobControl.BeginUpdate();
|
---|
| 289 | foreach (ListViewItem lvi in jobObjects) {
|
---|
| 290 | lvJobControl.Items.Add(lvi);
|
---|
[1937] | 291 | }
|
---|
[2109] | 292 | // actualization
|
---|
| 293 | lvJobControl.Groups.Add(lvJobCalculating);
|
---|
| 294 | lvJobControl.Groups.Add(lvJobFinished);
|
---|
| 295 | lvJobControl.Groups.Add(lvJobPending);
|
---|
| 296 | lvJobControl.EndUpdate();
|
---|
[1937] | 297 |
|
---|
[2109] | 298 | if (currentJob != null) {
|
---|
| 299 | JobClicked();
|
---|
| 300 | }
|
---|
[1937] | 301 | }
|
---|
[1598] | 302 | }
|
---|
[1937] | 303 | catch (Exception ex) {
|
---|
| 304 | closeFormEvent(true, true);
|
---|
| 305 | this.Close();
|
---|
| 306 | }
|
---|
[1598] | 307 | }
|
---|
| 308 |
|
---|
[1037] | 309 | private void AddClients() {
|
---|
[2026] | 310 | lvClientGroups = new List<ListViewGroup>();
|
---|
[1657] | 311 | clientList.Clear();
|
---|
| 312 | tvClientControl.Nodes.Clear();
|
---|
[2026] | 313 | try {
|
---|
| 314 | ResponseList<ClientGroup> clientGroups = ClientManager.GetAllClientGroups();
|
---|
[831] | 315 |
|
---|
[2110] | 316 | if (clientGroups != null && clientGroups.List != null) {
|
---|
| 317 | foreach (ClientGroup cg in clientGroups.List) {
|
---|
| 318 | AddClientOrGroup(cg, null);
|
---|
| 319 | }
|
---|
[1657] | 320 |
|
---|
[2110] | 321 | if (currentGroupNode != null) {
|
---|
| 322 | lvClientControl.Items.Clear();
|
---|
| 323 | lvClientControl.Groups.Clear();
|
---|
| 324 | AddGroupsToListView(currentGroupNode);
|
---|
| 325 | }
|
---|
| 326 | tvClientControl.ExpandAll();
|
---|
[2026] | 327 | }
|
---|
[1657] | 328 |
|
---|
[1723] | 329 | }
|
---|
[2026] | 330 | catch (FaultException fe) {
|
---|
| 331 | MessageBox.Show(fe.Message);
|
---|
| 332 | }
|
---|
[1645] | 333 | }
|
---|
[1512] | 334 |
|
---|
[1645] | 335 | private void AddClientOrGroup(ClientGroup clientGroup, TreeNode currentNode) {
|
---|
| 336 | currentNode = CreateTreeNode(clientGroup, currentNode);
|
---|
[1657] | 337 | List<ListViewItem> clientGroupList = new List<ListViewItem>();
|
---|
| 338 | ListViewGroup lvg;
|
---|
| 339 | if (string.IsNullOrEmpty(clientGroup.Name)) {
|
---|
| 340 | lvg = new ListViewGroup(NOGROUP, HorizontalAlignment.Left);
|
---|
| 341 | } else {
|
---|
| 342 | lvg = new ListViewGroup(clientGroup.Name, HorizontalAlignment.Left);
|
---|
| 343 | }
|
---|
| 344 | lvClientControl.Groups.Add(lvg);
|
---|
[2026] | 345 | lvg.Tag = clientGroup;
|
---|
| 346 | lvClientGroups.Add(lvg);
|
---|
[1645] | 347 | foreach (Resource resource in clientGroup.Resources) {
|
---|
| 348 | if (resource is ClientInfo) {
|
---|
[1723] | 349 | int percentageUsage = CapacityRam(((ClientInfo)resource).NrOfCores, ((ClientInfo)resource).NrOfFreeCores);
|
---|
| 350 | int usage = 3;
|
---|
| 351 | if ((((ClientInfo)resource).State != State.offline) &&
|
---|
| 352 | (((ClientInfo)resource).State != State.nullState)) {
|
---|
| 353 | if ((percentageUsage >= 0) && (percentageUsage <= 25)) {
|
---|
| 354 | usage = 0;
|
---|
| 355 | } else if ((percentageUsage > 25) && (percentageUsage <= 75)) {
|
---|
| 356 | usage = 1;
|
---|
| 357 | } else if ((percentageUsage > 75) && (percentageUsage <= 100)) {
|
---|
| 358 | usage = 2;
|
---|
| 359 | }
|
---|
| 360 | }
|
---|
| 361 | ListViewItem lvi = new ListViewItem(resource.Name, usage, lvg);
|
---|
[1645] | 362 | lvi.Tag = resource as ClientInfo;
|
---|
[1657] | 363 | clientGroupList.Add(lvi);
|
---|
[1645] | 364 | } else if (resource is ClientGroup) {
|
---|
| 365 | AddClientOrGroup(resource as ClientGroup, currentNode);
|
---|
[831] | 366 | }
|
---|
[1018] | 367 | }
|
---|
[1657] | 368 | clientList.Add(clientGroup.Id, clientGroupList);
|
---|
[1018] | 369 | }
|
---|
[956] | 370 |
|
---|
[1645] | 371 | private TreeNode CreateTreeNode(ClientGroup clientGroup, TreeNode currentNode) {
|
---|
[1657] | 372 | TreeNode tn;
|
---|
| 373 | if (string.IsNullOrEmpty(clientGroup.Name)) {
|
---|
| 374 | tn = new TreeNode(NOGROUP);
|
---|
[1645] | 375 | } else {
|
---|
[1657] | 376 | tn = new TreeNode(clientGroup.Name);
|
---|
[1645] | 377 | }
|
---|
| 378 | tn.Tag = clientGroup;
|
---|
| 379 | if (currentNode == null) {
|
---|
| 380 | tvClientControl.Nodes.Add(tn);
|
---|
| 381 | } else {
|
---|
| 382 | currentNode.Nodes.Add(tn);
|
---|
| 383 | }
|
---|
| 384 | return tn;
|
---|
| 385 | }
|
---|
[1483] | 386 |
|
---|
[1937] | 387 | private void AddGroupsToListView(TreeNode node) {
|
---|
| 388 | if (node != null) {
|
---|
| 389 | ListViewGroup lvg = new ListViewGroup(node.Text, HorizontalAlignment.Left);
|
---|
| 390 | lvClientControl.Groups.Add(lvg);
|
---|
[2026] | 391 | lvg.Tag = node.Tag;
|
---|
[1937] | 392 | foreach (ListViewItem item in clientList[((ClientGroup)node.Tag).Id]) {
|
---|
| 393 | item.Group = lvg;
|
---|
| 394 | lvClientControl.Items.Add(item);
|
---|
[1483] | 395 | }
|
---|
[1018] | 396 |
|
---|
[1937] | 397 | if (node.Nodes != null) {
|
---|
| 398 | foreach (TreeNode curNode in node.Nodes) {
|
---|
| 399 | AddGroupsToListView(curNode);
|
---|
[1832] | 400 | }
|
---|
[1512] | 401 | }
|
---|
| 402 | }
|
---|
[1136] | 403 | }
|
---|
| 404 |
|
---|
| 405 | /// <summary>
|
---|
[1581] | 406 | /// if one job is clicked, the details for the clicked job are shown
|
---|
| 407 | /// in the second panel
|
---|
[1136] | 408 | /// </summary>
|
---|
| 409 | private void JobClicked() {
|
---|
[1512] | 410 | plJobDetails.Visible = true;
|
---|
[1774] | 411 | lvJobDetails.Items.Clear();
|
---|
[1937] | 412 |
|
---|
[1512] | 413 | lvSnapshots.Enabled = true;
|
---|
[1937] | 414 |
|
---|
[1717] | 415 | if (currentJob.State == State.offline) {
|
---|
| 416 | pbJobControl.Image = ilLargeImgJob.Images[2];
|
---|
| 417 | } else if (currentJob.State == State.calculating) {
|
---|
| 418 | pbJobControl.Image = ilLargeImgJob.Images[1];
|
---|
| 419 | } else if (currentJob.State == State.finished) {
|
---|
| 420 | pbJobControl.Image = ilLargeImgJob.Images[0];
|
---|
| 421 | }
|
---|
[1753] | 422 |
|
---|
[1136] | 423 | lblJobName.Text = currentJob.Id.ToString();
|
---|
| 424 | progressJob.Value = (int)(currentJob.Percentage * 100);
|
---|
| 425 | lblProgress.Text = (int)(currentJob.Percentage * 100) + "% calculated";
|
---|
[1937] | 426 |
|
---|
[1774] | 427 | ListViewItem lvi = new ListViewItem();
|
---|
| 428 | lvi.Text = "User:";
|
---|
| 429 | lvi.SubItems.Add(currentJob.UserId.ToString());
|
---|
| 430 | lvJobDetails.Items.Add(lvi);
|
---|
| 431 |
|
---|
[1832] | 432 | lvi = null;
|
---|
| 433 | lvi = new ListViewItem();
|
---|
| 434 | lvi.Text = "created at:";
|
---|
| 435 | lvi.SubItems.Add(currentJob.DateCreated.ToString());
|
---|
| 436 | lvJobDetails.Items.Add(lvi);
|
---|
[1774] | 437 |
|
---|
[1136] | 438 | if (currentJob.ParentJob != null) {
|
---|
[1774] | 439 | lvi = null;
|
---|
| 440 | lvi = new ListViewItem();
|
---|
| 441 | lvi.Text = "Parent job:";
|
---|
| 442 | lvi.SubItems.Add(currentJob.ParentJob.ToString());
|
---|
| 443 | lvJobDetails.Items.Add(lvi);
|
---|
[1937] | 444 | }
|
---|
[1774] | 445 |
|
---|
| 446 | lvi = null;
|
---|
| 447 | lvi = new ListViewItem();
|
---|
| 448 | lvi.Text = "Priority:";
|
---|
| 449 | lvi.SubItems.Add(currentJob.Priority.ToString());
|
---|
| 450 | lvJobDetails.Items.Add(lvi);
|
---|
| 451 |
|
---|
[1956] | 452 | if (currentJob.Project != null) {
|
---|
| 453 | lvi = null;
|
---|
| 454 | lvi = new ListViewItem();
|
---|
| 455 | lvi.Text = "Project:";
|
---|
| 456 | lvi.SubItems.Add(currentJob.Project.Name.ToString());
|
---|
| 457 | lvJobDetails.Items.Add(lvi);
|
---|
| 458 | }
|
---|
| 459 |
|
---|
[1136] | 460 | if (currentJob.Client != null) {
|
---|
[1774] | 461 | lvi = null;
|
---|
| 462 | lvi = new ListViewItem();
|
---|
| 463 | lvi.Text = "Calculation begin:";
|
---|
| 464 | lvi.SubItems.Add(currentJob.DateCalculated.ToString());
|
---|
| 465 | lvJobDetails.Items.Add(lvi);
|
---|
[1495] | 466 |
|
---|
[1774] | 467 |
|
---|
| 468 | lvi = null;
|
---|
| 469 | lvi = new ListViewItem();
|
---|
| 470 | lvi.Text = "Client calculated:";
|
---|
| 471 | lvi.SubItems.Add(currentJob.Client.Name.ToString());
|
---|
| 472 | lvJobDetails.Items.Add(lvi);
|
---|
| 473 |
|
---|
[1173] | 474 | if (currentJob.State == State.finished) {
|
---|
| 475 | IJobManager jobManager =
|
---|
| 476 | ServiceLocator.GetJobManager();
|
---|
[2099] | 477 | ResponseObject<JobResult> jobRes = jobManager.GetLastJobResultOf(currentJob.Id);
|
---|
[1832] | 478 |
|
---|
[2109] | 479 | if (jobRes != null && jobRes.Obj != null) {
|
---|
| 480 | lvi = null;
|
---|
| 481 | lvi = new ListViewItem();
|
---|
| 482 | lvi.Text = "Calculation ended:";
|
---|
| 483 | lvi.SubItems.Add(jobRes.Obj.DateFinished.ToString());
|
---|
| 484 | lvJobDetails.Items.Add(lvi);
|
---|
| 485 | }
|
---|
[1173] | 486 | }
|
---|
[1495] | 487 | }
|
---|
[1173] | 488 | if (currentJob.State != State.offline) {
|
---|
[1590] | 489 | lvSnapshots.Items.Clear();
|
---|
[1832] | 490 | GetSnapshotList();
|
---|
[1495] | 491 | } else {
|
---|
[1512] | 492 | lvSnapshots.Visible = false;
|
---|
[1148] | 493 | }
|
---|
[1136] | 494 | }
|
---|
| 495 |
|
---|
[1937] | 496 | /// <summary>
|
---|
| 497 | /// if one client is clicked, the details for the clicked client are shown
|
---|
| 498 | /// in the second panel
|
---|
| 499 | /// </summary>
|
---|
| 500 | private void ClientClicked() {
|
---|
| 501 | plClientDetails.Visible = true;
|
---|
| 502 |
|
---|
| 503 | if (currentClient != null) {
|
---|
| 504 | int percentageUsage = CapacityRam(currentClient.NrOfCores, currentClient.NrOfFreeCores);
|
---|
| 505 | int usage = 3;
|
---|
| 506 | if ((currentClient.State != State.offline) && (currentClient.State != State.nullState)) {
|
---|
| 507 | if ((percentageUsage >= 0) && (percentageUsage <= 25)) {
|
---|
| 508 | usage = 0;
|
---|
| 509 | } else if ((percentageUsage > 25) && (percentageUsage <= 75)) {
|
---|
| 510 | usage = 1;
|
---|
| 511 | } else if ((percentageUsage > 75) && (percentageUsage <= 100)) {
|
---|
| 512 | usage = 2;
|
---|
| 513 | }
|
---|
| 514 | }
|
---|
| 515 | pbClientControl.Image = ilLargeImgClient.Images[usage];
|
---|
| 516 | lblClientName.Text = currentClient.Name;
|
---|
| 517 | lblLogin.Text = currentClient.Login.ToString();
|
---|
| 518 | lblState.Text = currentClient.State.ToString();
|
---|
| 519 | }
|
---|
| 520 | }
|
---|
| 521 |
|
---|
| 522 | private void RefreshForm() {
|
---|
[1483] | 523 | foreach (Changes change in changes) {
|
---|
| 524 | if (change.Types == Type.Job) {
|
---|
| 525 | RefreshJob(change);
|
---|
| 526 | }
|
---|
| 527 | }
|
---|
| 528 | }
|
---|
| 529 |
|
---|
| 530 | private void RefreshJob(Changes change) {
|
---|
| 531 | if (change.ChangeType == Change.Update) {
|
---|
| 532 | for (int i = 0; i < lvJobControl.Items.Count; i++) {
|
---|
| 533 | if (lvJobControl.Items[i].Text == change.ID.ToString()) {
|
---|
[1723] | 534 | foreach (Job job in jobs.List) {
|
---|
| 535 | if (job.Id == change.ID) {
|
---|
| 536 | lvJobControl.Items[i].Tag = job;
|
---|
[2109] | 537 | if (currentJob != null) {
|
---|
| 538 | if (currentJob.Id == change.ID) {
|
---|
| 539 | currentJob = job;
|
---|
| 540 | JobClicked();
|
---|
| 541 | }
|
---|
[1937] | 542 | }
|
---|
[1723] | 543 | break;
|
---|
| 544 | }
|
---|
| 545 | }
|
---|
[1483] | 546 | State state = jobs.List[change.Position].State;
|
---|
| 547 | if (state == State.finished) {
|
---|
| 548 | lvJobControl.Items[i].Group = jobGroup[1];
|
---|
[1717] | 549 | lvJobControl.Items[i].ImageIndex = 0;
|
---|
[1483] | 550 | } else if (state == State.calculating) {
|
---|
| 551 | lvJobControl.Items[i].Group = jobGroup[0];
|
---|
[1717] | 552 | lvJobControl.Items[i].ImageIndex = 1;
|
---|
[2109] | 553 | } else if (state == State.offline || state == State.pending) {
|
---|
[1483] | 554 | lvJobControl.Items[i].Group = jobGroup[2];
|
---|
[1717] | 555 | lvJobControl.Items[i].ImageIndex = 2;
|
---|
[1483] | 556 | }
|
---|
| 557 | lvJobControl.Refresh();
|
---|
| 558 | }
|
---|
| 559 | }
|
---|
| 560 | } else if (change.ChangeType == Change.Create) {
|
---|
[1937] | 561 |
|
---|
[1483] | 562 | ListViewItem lvi = new ListViewItem(
|
---|
[1717] | 563 | change.ID.ToString(), 2, jobGroup[2]);
|
---|
[1937] | 564 | foreach (Job job in jobs.List) {
|
---|
| 565 | if (job.Id == change.ID) {
|
---|
| 566 | lvi.Tag = job;
|
---|
| 567 | break;
|
---|
| 568 | }
|
---|
| 569 | }
|
---|
[1483] | 570 | lvJobControl.Items.Add(lvi);
|
---|
| 571 |
|
---|
| 572 | } else if (change.ChangeType == Change.Delete) {
|
---|
| 573 | for (int i = 0; i < lvJobControl.Items.Count; i++) {
|
---|
| 574 | if (change.ID.ToString() == lvJobControl.Items[i].Text.ToString()) {
|
---|
| 575 | lvJobControl.Items[i].Remove();
|
---|
| 576 | break;
|
---|
| 577 | }
|
---|
| 578 | }
|
---|
| 579 | }
|
---|
| 580 | }
|
---|
| 581 |
|
---|
[1595] | 582 |
|
---|
[1148] | 583 | #region Eventhandlers
|
---|
[1136] | 584 | /// <summary>
|
---|
[794] | 585 | /// Send event to Login-GUI when closing
|
---|
| 586 | /// </summary>
|
---|
| 587 | /// <param name="sender"></param>
|
---|
| 588 | /// <param name="e"></param>
|
---|
[1037] | 589 | private void Close_Click(object sender, EventArgs e) {
|
---|
[794] | 590 | if (closeFormEvent != null) {
|
---|
[1030] | 591 | closeFormEvent(true, false);
|
---|
[794] | 592 | }
|
---|
| 593 | this.Close();
|
---|
| 594 | }
|
---|
| 595 |
|
---|
| 596 | /// <summary>
|
---|
| 597 | /// Send evnt to Login-GUI when closing
|
---|
| 598 | /// </summary>
|
---|
| 599 | /// <param name="sender"></param>
|
---|
| 600 | /// <param name="e"></param>
|
---|
| 601 | private void HiveServerConsoleInformation_FormClosing(object sender, FormClosingEventArgs e) {
|
---|
| 602 | if (closeFormEvent != null) {
|
---|
[1030] | 603 | closeFormEvent(true, false);
|
---|
[794] | 604 | }
|
---|
| 605 | }
|
---|
[956] | 606 |
|
---|
[1136] | 607 | private void AddJob_Click(object sender, EventArgs e) {
|
---|
[1018] | 608 | AddJobForm newForm = new AddJobForm();
|
---|
[956] | 609 | newForm.Show();
|
---|
[1581] | 610 | newForm.addJobEvent += new addDelegate(updaterWoker.RunWorkerAsync);
|
---|
[956] | 611 | }
|
---|
| 612 |
|
---|
[1136] | 613 | private void OnLVJobControlClicked(object sender, EventArgs e) {
|
---|
[1937] | 614 | currentJob = (Job)lvJobControl.SelectedItems[0].Tag;
|
---|
[1136] | 615 | JobClicked();
|
---|
[1098] | 616 | }
|
---|
| 617 |
|
---|
[1126] | 618 | private void lvJobControl_MouseMove(object sender, MouseEventArgs e) {
|
---|
| 619 | if ((lvJobControl.GetItemAt(e.X, e.Y) != null) &&
|
---|
| 620 | (lvJobControl.GetItemAt(e.X, e.Y).ToolTipText != null)) {
|
---|
| 621 | tt.SetToolTip(lvJobControl, lvJobControl.GetItemAt(e.X, e.Y).ToolTipText);
|
---|
| 622 | }
|
---|
| 623 | }
|
---|
[1261] | 624 |
|
---|
[1937] | 625 | private void lvJobControl_MouseUp(object sender, MouseEventArgs e) {
|
---|
| 626 | // If the right mouse button was clicked and released,
|
---|
| 627 | // display the shortcut menu assigned to the ListView.
|
---|
| 628 | lvJobControl.ContextMenuStrip.Items.Clear();
|
---|
| 629 | ListViewHitTestInfo hitTestInfo = lvJobControl.HitTest(e.Location);
|
---|
| 630 | if (e.Button == MouseButtons.Right && hitTestInfo.Item != null && lvJobControl.SelectedItems.Count == 1) {
|
---|
| 631 | Job selectedJob = (Job)lvJobControl.SelectedItems[0].Tag;
|
---|
[1483] | 632 |
|
---|
[1937] | 633 | if (selectedJob != null && selectedJob.State == State.calculating) {
|
---|
| 634 | lvJobControl.ContextMenuStrip.Items.Add(menuItemAbortJob);
|
---|
| 635 | lvJobControl.ContextMenuStrip.Items.Add(menuItemGetSnapshot);
|
---|
| 636 | }
|
---|
| 637 | }
|
---|
| 638 | lvJobControl.ContextMenuStrip.Show(new Point(e.X, e.Y));
|
---|
| 639 | }
|
---|
[1495] | 640 |
|
---|
[1937] | 641 | private void tvClientControl_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) {
|
---|
| 642 | lvClientControl.Items.Clear();
|
---|
| 643 | lvClientControl.Groups.Clear();
|
---|
[2007] | 644 | currentGroupNode = e.Node;
|
---|
[1937] | 645 | AddGroupsToListView(e.Node);
|
---|
| 646 | }
|
---|
[1483] | 647 |
|
---|
[1937] | 648 | private void groupToolStripMenuItem_Click(object sender, EventArgs e) {
|
---|
| 649 | AddGroup addgroup = new AddGroup();
|
---|
| 650 | parentgroup = Guid.Empty;
|
---|
| 651 | if ((tvClientControl.SelectedNode != null) && (((ClientGroup)tvClientControl.SelectedNode.Tag).Id != Guid.Empty)) {
|
---|
| 652 | parentgroup = ((ClientGroup)tvClientControl.SelectedNode.Tag).Id;
|
---|
| 653 | }
|
---|
| 654 | addgroup.addGroupEvent += new AddGroupDelegate(addgroup_addGroupEvent);
|
---|
| 655 | addgroup.Show();
|
---|
| 656 | }
|
---|
[1483] | 657 |
|
---|
[1956] | 658 | private void projectToolStripMenuItem_Click(object sender, EventArgs e) {
|
---|
| 659 | AddProject addproject = new AddProject();
|
---|
| 660 | addproject.AddProjectEvent += new AddProjectDelegate(addproject_AddProjectEvent);
|
---|
| 661 | addproject.Show();
|
---|
| 662 | }
|
---|
| 663 |
|
---|
[1937] | 664 | private void OnLVClientClicked(object sender, EventArgs e) {
|
---|
| 665 | currentClient = (ClientInfo)lvClientControl.SelectedItems[0].Tag;
|
---|
| 666 | ClientClicked();
|
---|
| 667 | }
|
---|
[1483] | 668 |
|
---|
[1937] | 669 | private void tvClientControl_MouseUp(object sender, MouseEventArgs e) {
|
---|
| 670 | // If the right mouse button was clicked and released,
|
---|
| 671 | // display the shortcut menu assigned to the ListView.
|
---|
| 672 | contextMenuGroup.Items.Clear();
|
---|
| 673 | TreeViewHitTestInfo hitTestInfo = tvClientControl.HitTest(e.Location);
|
---|
| 674 | tvClientControl.SelectedNode = hitTestInfo.Node;
|
---|
| 675 | if (e.Button != MouseButtons.Right) return;
|
---|
[2007] | 676 | if (hitTestInfo.Node != null) {
|
---|
| 677 | Resource selectedGroup = (Resource)tvClientControl.SelectedNode.Tag;
|
---|
[1483] | 678 |
|
---|
[2007] | 679 | if (selectedGroup != null) {
|
---|
[1937] | 680 | contextMenuGroup.Items.Add(menuItemAddGroup);
|
---|
[2007] | 681 | contextMenuGroup.Items.Add(menuItemDeleteGroup);
|
---|
[1937] | 682 | }
|
---|
[2007] | 683 | } else {
|
---|
| 684 | contextMenuGroup.Items.Add(menuItemAddGroup);
|
---|
| 685 | }
|
---|
| 686 | tvClientControl.ContextMenuStrip.Show(tvClientControl, new Point(e.X, e.Y));
|
---|
[1937] | 687 | }
|
---|
[1495] | 688 |
|
---|
[1956] | 689 | private void addproject_AddProjectEvent(string name) {
|
---|
| 690 | IJobManager jobManager = ServiceLocator.GetJobManager();
|
---|
| 691 |
|
---|
| 692 | Project pg = new Project() { Name = name };
|
---|
| 693 | jobManager.CreateProject(pg);
|
---|
| 694 |
|
---|
| 695 | }
|
---|
| 696 |
|
---|
[1937] | 697 | private void addgroup_addGroupEvent(string name) {
|
---|
| 698 | IClientManager clientManager = ServiceLocator.GetClientManager();
|
---|
[1483] | 699 |
|
---|
[1937] | 700 | if (parentgroup != Guid.Empty) {
|
---|
| 701 | ClientGroup cg = new ClientGroup() { Name = name };
|
---|
| 702 | ResponseObject<ClientGroup> respcg = clientManager.AddClientGroup(cg);
|
---|
| 703 | Response res = clientManager.AddResourceToGroup(parentgroup, respcg.Obj);
|
---|
| 704 | if (res != null && !res.Success) {
|
---|
| 705 | MessageBox.Show(res.StatusMessage, "Error adding Group", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
---|
| 706 | }
|
---|
| 707 | } else {
|
---|
| 708 | ClientGroup cg = new ClientGroup() { Name = name };
|
---|
| 709 | clientManager.AddClientGroup(cg);
|
---|
[1956] | 710 | }
|
---|
[2007] | 711 | AddClients();
|
---|
[1937] | 712 | }
|
---|
[1483] | 713 |
|
---|
[1956] | 714 |
|
---|
[1937] | 715 | private void Refresh_Click(object sender, EventArgs e) {
|
---|
| 716 | Form overlayingForm = new Form();
|
---|
[1483] | 717 |
|
---|
[1937] | 718 | overlayingForm.Show();
|
---|
| 719 | overlayingForm.FormBorderStyle = FormBorderStyle.None;
|
---|
| 720 | overlayingForm.BackColor = Color.Gray;
|
---|
| 721 | overlayingForm.Opacity = 0.4;
|
---|
| 722 | overlayingForm.Size = this.Size;
|
---|
| 723 | overlayingForm.Location = this.Location;
|
---|
[1483] | 724 |
|
---|
[1937] | 725 | AddClients();
|
---|
[1483] | 726 |
|
---|
[1937] | 727 | overlayingForm.Close();
|
---|
| 728 | }
|
---|
[1483] | 729 |
|
---|
[1937] | 730 | private void largeIconsToolStripMenuItem_Click(object sender, EventArgs e) {
|
---|
| 731 | lvClientControl.View = View.LargeIcon;
|
---|
| 732 | lvJobControl.View = View.LargeIcon;
|
---|
| 733 | largeIconsToolStripMenuItem.CheckState = CheckState.Checked;
|
---|
| 734 | smallIconsToolStripMenuItem.CheckState = CheckState.Unchecked;
|
---|
| 735 | listToolStripMenuItem.CheckState = CheckState.Unchecked;
|
---|
| 736 | }
|
---|
[1483] | 737 |
|
---|
[1937] | 738 | private void smallIconsToolStripMenuItem_Click(object sender, EventArgs e) {
|
---|
| 739 | lvClientControl.View = View.SmallIcon;
|
---|
| 740 | lvJobControl.View = View.SmallIcon;
|
---|
| 741 | largeIconsToolStripMenuItem.CheckState = CheckState.Unchecked;
|
---|
| 742 | smallIconsToolStripMenuItem.CheckState = CheckState.Checked;
|
---|
| 743 | listToolStripMenuItem.CheckState = CheckState.Unchecked;
|
---|
| 744 | }
|
---|
[1483] | 745 |
|
---|
[1937] | 746 | private void listToolStripMenuItem_Click(object sender, EventArgs e) {
|
---|
| 747 | lvClientControl.View = View.List;
|
---|
| 748 | lvJobControl.View = View.List;
|
---|
| 749 | largeIconsToolStripMenuItem.CheckState = CheckState.Unchecked;
|
---|
| 750 | smallIconsToolStripMenuItem.CheckState = CheckState.Unchecked;
|
---|
| 751 | listToolStripMenuItem.CheckState = CheckState.Checked;
|
---|
[1483] | 752 | }
|
---|
[2007] | 753 |
|
---|
| 754 | private void tvClientControl_DragLeave(object sender, EventArgs e) {
|
---|
| 755 | foreach (TreeNode node in tvClientControl.Nodes) {
|
---|
| 756 | node.BackColor = Color.White;
|
---|
| 757 | node.ForeColor = Color.Black;
|
---|
| 758 | }
|
---|
| 759 | }
|
---|
[1483] | 760 | #endregion
|
---|
| 761 |
|
---|
| 762 | #region Helper methods
|
---|
| 763 |
|
---|
| 764 | private void CloneList(ResponseList<Job> oldList, out IDictionary<int, Job> newList) {
|
---|
| 765 | newList = new Dictionary<int, Job>();
|
---|
| 766 | for (int i = 0; i < oldList.List.Count; i++) {
|
---|
| 767 | newList.Add(i, oldList.List[i]);
|
---|
| 768 | }
|
---|
| 769 | }
|
---|
| 770 |
|
---|
| 771 | private bool IsEqual(ClientInfo ci1, ClientInfo ci2) {
|
---|
| 772 | if (ci2 == null) {
|
---|
| 773 | return false;
|
---|
| 774 | }
|
---|
| 775 | if (ci1.Id.Equals(ci2.Id)) {
|
---|
| 776 | return true;
|
---|
| 777 | } else return false;
|
---|
| 778 | }
|
---|
| 779 |
|
---|
[1590] | 780 | private int CapacityRam(int noCores, int freeCores) {
|
---|
[1657] | 781 | if (noCores > 0) {
|
---|
| 782 | int capacity = ((noCores - freeCores) / noCores) * 100;
|
---|
| 783 | return capacity;
|
---|
| 784 | }
|
---|
| 785 | return 100;
|
---|
[1590] | 786 | }
|
---|
| 787 |
|
---|
[1483] | 788 | private void GetDelta(IList<Job> oldJobs, IDictionary<int, Job> helpJobs) {
|
---|
| 789 | bool found = false;
|
---|
[1495] | 790 | for (int i = 0; i < jobs.List.Count; i++) {
|
---|
[1483] | 791 | Job job = jobs.List[i];
|
---|
| 792 | for (int j = 0; j < oldJobs.Count; j++) {
|
---|
| 793 |
|
---|
| 794 | Job jobold = oldJobs[j];
|
---|
| 795 |
|
---|
| 796 | if (job.Id.Equals(jobold.Id)) {
|
---|
| 797 |
|
---|
| 798 | found = true;
|
---|
[1717] | 799 | bool change = false;
|
---|
| 800 | if (job.State != jobold.State) {
|
---|
| 801 | change = true;
|
---|
| 802 | }
|
---|
[1483] | 803 | if (job.State != State.offline) {
|
---|
[1590] | 804 | if ((!IsEqual(job.Client, jobold.Client)) || (job.State != jobold.State)
|
---|
[1512] | 805 | || (job.Percentage != jobold.Percentage)) {
|
---|
[1717] | 806 | change = true;
|
---|
[1483] | 807 | }
|
---|
| 808 | } else if (job.DateCalculated != jobold.DateCalculated) {
|
---|
[1717] | 809 | change = true;
|
---|
| 810 | }
|
---|
| 811 | if (change) {
|
---|
[1483] | 812 | changes.Add(new Changes { Types = Type.Job, ID = job.Id, ChangeType = Change.Update, Position = i });
|
---|
| 813 | }
|
---|
| 814 |
|
---|
| 815 | int removeAt = -1;
|
---|
| 816 | foreach (KeyValuePair<int, Job> kvp in helpJobs) {
|
---|
| 817 | if (job.Id.Equals(kvp.Value.Id)) {
|
---|
| 818 | removeAt = kvp.Key;
|
---|
| 819 | break;
|
---|
| 820 | }
|
---|
| 821 | }
|
---|
| 822 | if (removeAt >= 0) {
|
---|
| 823 | helpJobs.Remove(removeAt);
|
---|
| 824 | }
|
---|
| 825 | break;
|
---|
| 826 | }
|
---|
| 827 |
|
---|
| 828 | }
|
---|
| 829 | if (found == false) {
|
---|
| 830 | changes.Add(new Changes { Types = Type.Job, ID = job.Id, ChangeType = Change.Create });
|
---|
| 831 | }
|
---|
| 832 | found = false;
|
---|
| 833 | }
|
---|
| 834 | foreach (KeyValuePair<int, Job> kvp in helpJobs) {
|
---|
| 835 | changes.Add(new Changes { Types = Type.Job, ID = kvp.Value.Id, ChangeType = Change.Delete, Position = kvp.Key });
|
---|
| 836 | }
|
---|
| 837 | }
|
---|
| 838 |
|
---|
[1581] | 839 | private void GetSnapshotList() {
|
---|
[1483] | 840 |
|
---|
[1581] | 841 | lvSnapshots.Items.Clear();
|
---|
[1590] | 842 | IJobManager jobManager = ServiceLocator.GetJobManager();
|
---|
| 843 |
|
---|
[1832] | 844 | ResponseList<JobResult> jobRes = jobManager.GetAllJobResults(currentJob.Id);
|
---|
[1590] | 845 |
|
---|
[1832] | 846 | if (jobRes.List != null) {
|
---|
| 847 | foreach (JobResult jobresult in jobRes.List) {
|
---|
[1939] | 848 | ListViewItem curSnapshot = new ListViewItem(jobresult.ClientId.ToString());
|
---|
[1832] | 849 | double percentage = jobresult.Percentage * 100;
|
---|
| 850 | curSnapshot.SubItems.Add(percentage.ToString() + " %");
|
---|
| 851 | curSnapshot.SubItems.Add(jobresult.Timestamp.ToString());
|
---|
| 852 | lvSnapshots.Items.Add(curSnapshot);
|
---|
| 853 | }
|
---|
| 854 | }
|
---|
[1590] | 855 |
|
---|
[1832] | 856 | if ((jobRes.List == null) && (jobRes.List.Count == 0)) {
|
---|
| 857 | lvSnapshots.Visible = false;
|
---|
| 858 | } else {
|
---|
| 859 | lvSnapshots.Visible = true;
|
---|
| 860 | }
|
---|
| 861 |
|
---|
[1483] | 862 | }
|
---|
| 863 |
|
---|
[1581] | 864 | #endregion
|
---|
[1483] | 865 |
|
---|
[2007] | 866 |
|
---|
| 867 |
|
---|
[794] | 868 | }
|
---|
[844] | 869 | } |
---|