#region License Information
/* HeuristicLab
* Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
*
* This file is part of HeuristicLab.
*
* HeuristicLab is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* HeuristicLab is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with HeuristicLab. If not, see .
*/
#endregion
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using HeuristicLab.Hive.Contracts.Interfaces;
using HeuristicLab.Hive.Contracts.BusinessObjects;
using HeuristicLab.Hive.Contracts;
using System.Threading;
using System.ServiceModel;
using HeuristicLab.Tracing;
namespace HeuristicLab.Hive.Server.ServerConsole {
///
/// if form is closed the loginform gets an information
///
///
///
public delegate void closeForm(bool cf, bool error);
public delegate void updateListView(JobDataFetcher fetcher, ListView sender, int category);
public partial class HiveServerManagementConsole : Form {
public event closeForm closeFormEvent;
#region private variables
private ResponseList jobs = null;
List jobGroup;
private Dictionary> clientList = new Dictionary>();
private List changes = new List();
private JobDto currentJob = null;
private ClientDto currentClient = null;
private TreeNode currentGroupNode = null;
Guid parentgroup = Guid.Empty;
private ToolTip tt = new ToolTip();
private const string NOGROUP = "No group";
private TreeNode hoverNode;
private List lvClientGroups;
private JobDataFetcher jdfFinished = null;
private JobDataFetcher jdfOffline = null;
private JobDataFetcher jdfCalculating = null;
#endregion
#region Properties
private IClientManager ClientManager {
get {
try {
return ServiceLocator.GetClientManager();
}
catch (FaultException ex) {
MessageBox.Show(ex.Message);
}
return null;
}
}
#endregion
public HiveServerManagementConsole() {
InitializeComponent();
Init();
AddClients();
//AddJobs();
StartAutoUpdateTimers();
//timerSyncronize.Start();
}
private void StartAutoUpdateTimers() {
jdfCalculating.NewDataAvailable += new EventHandler(jdf_NewDataAvailable);
jdfOffline.NewDataAvailable += new EventHandler(jdf_NewDataAvailable);
jdfFinished.NewDataAvailable += new EventHandler(jdf_NewDataAvailable);
jdfFinished.Start();
jdfOffline.Start();
jdfCalculating.Start();
}
void jdf_NewDataAvailable(object sender, EventArgs e) {
JobDataFetcher fetcher = (JobDataFetcher) sender;
if (fetcher.PollStates.Contains(State.finished)) {
updateJobListView(fetcher, lv_finishedJobs, 0);
} else if(fetcher.PollStates.Contains(State.calculating)) {
updateJobListView(fetcher, lv_calculatingJobs, 1);
} else if (fetcher.PollStates.Contains(State.offline)) {
updateJobListView(fetcher, lv_offlineJobs, 2);
}
}
private void updateJobListView(JobDataFetcher fetcher, ListView listView, int category) {
if (listView.InvokeRequired) {
listView.Invoke(new updateListView(updateJobListView), new object[] { fetcher, listView, category });
} else {
listView.BeginUpdate();
listView.Items.Clear();
foreach (JobDto job in fetcher.CachedJobs) {
ListViewItem lvi = new ListViewItem(job.Id.ToString(), category);
lvi.Tag = job;
listView.Items.Add(lvi);
}
listView.EndUpdate();
}
}
private void Init() {
jdfFinished = new JobDataFetcher(new State[] {State.finished}, 50);
jdfCalculating = new JobDataFetcher(new State[] {State.calculating}, 50);
jdfOffline = new JobDataFetcher(new State[] {State.offline}, 50);
cmb_finishedJob_count.SelectedItem = "50";
cmb_offlineJob_count.SelectedItem = "50";
cmb_calculatingJob_count.SelectedItem = "50";
calcToolStripAbortItem.Click += (s, e) => {
if(lv_calculatingJobs.SelectedItems.Count > 0) {
ServiceLocator.GetJobManager().AbortJob(((JobDto) lv_calculatingJobs.SelectedItems[0].Tag).Id);
}
};
offlineItemAbortJob.Click += (s, e) => {
if (lv_offlineJobs.SelectedItems.Count > 0) {
ServiceLocator.GetJobManager().AbortJob(((JobDto)lv_offlineJobs.SelectedItems[0].Tag).Id);
}
};
//adding group
menuItemAddGroup.Click += (s, e) => {
AddGroup addgroup = new AddGroup();
parentgroup = Guid.Empty;
if ((tvClientControl.SelectedNode != null) && (((ClientGroupDto)tvClientControl.SelectedNode.Tag).Id != Guid.Empty)) {
parentgroup = ((ClientGroupDto)tvClientControl.SelectedNode.Tag).Id;
}
addgroup.addGroupEvent += new AddGroupDelegate(addgroup_addGroupEvent);
addgroup.Show();
};
//adding group
menuItemDeleteGroup.Click += (s, e) => {
IClientManager clientManager = ServiceLocator.GetClientManager();
if (tvClientControl.SelectedNode != null) {
Response resp = clientManager.DeleteClientGroup(((ClientGroupDto)tvClientControl.SelectedNode.Tag).Id);
if (tvClientControl.SelectedNode == currentGroupNode) {
currentGroupNode = null;
}
tvClientControl.Nodes.Remove(tvClientControl.SelectedNode);
AddClients();
}
};
menuItemOpenCalendar.Click += (s, e) => {
if (tvClientControl.SelectedNode != null) {
CgCalendar cal = new CgCalendar(((ClientGroupDto)tvClientControl.SelectedNode.Tag).Id, ((ClientGroupDto)tvClientControl.SelectedNode.Tag).Name);
cal.Show();
}
};
// drag item to treeview
lvClientControl.ItemDrag += delegate(object sender, ItemDragEventArgs e) {
List itemIDs = new List((sender as ListView).SelectedItems.Count);
foreach (ListViewItem item in (sender as ListView).SelectedItems) {
itemIDs.Add(item.Name);
}
(sender as ListView).DoDragDrop(itemIDs.ToArray(), DragDropEffects.Move);
};
// drag enter on treeview
tvClientControl.DragEnter += delegate(object sender, DragEventArgs e) {
e.Effect = DragDropEffects.Move;
};
// drag over
tvClientControl.DragOver += delegate(object sender, DragEventArgs e) {
Point mouseLocation = tvClientControl.PointToClient(new Point(e.X, e.Y));
TreeNode node = tvClientControl.GetNodeAt(mouseLocation);
if (node != null && ((ClientGroupDto)node.Tag).Id != Guid.Empty) {
e.Effect = DragDropEffects.Move;
if (hoverNode == null) {
node.BackColor = Color.LightBlue;
node.ForeColor = Color.White;
hoverNode = node;
} else if (hoverNode != node) {
hoverNode.BackColor = Color.White;
hoverNode.ForeColor = Color.Black;
node.BackColor = Color.LightBlue;
node.ForeColor = Color.White;
hoverNode = node;
}
} else {
e.Effect = DragDropEffects.None;
}
};
// drag drop event
tvClientControl.DragDrop += delegate(object sender, DragEventArgs e) {
if (e.Data.GetDataPresent(typeof(string[]))) {
Point dropLocation = (sender as TreeView).PointToClient(new Point(e.X, e.Y));
TreeNode dropNode = (sender as TreeView).GetNodeAt(dropLocation);
if (((ClientGroupDto)dropNode.Tag).Id != Guid.Empty) {
Dictionary clients = new Dictionary();
foreach (ListViewItem lvi in lvClientControl.SelectedItems) {
Guid groupId = Guid.Empty;
foreach (ListViewGroup lvg in lvClientGroups) {
if (lvi.Group.Header == ((ClientGroupDto)lvg.Tag).Name) {
groupId = ((ClientGroupDto)lvg.Tag).Id;
}
}
clients.Add((ClientDto)lvi.Tag, groupId);
}
ChangeGroup(clients, ((ClientGroupDto)dropNode.Tag).Id);
}
tvClientControl_DragLeave(null, EventArgs.Empty);
AddClients();
}
};
}
///
/// Change client to other group
///
/// list of clients
/// group of clients
private void ChangeGroup(Dictionary clients, Guid clientgroupID) {
IClientManager clientManager = ServiceLocator.GetClientManager();
foreach (KeyValuePair client in clients) {
if (client.Key.Id != Guid.Empty) {
Response resp = clientManager.DeleteResourceFromGroup(client.Value, client.Key.Id);
}
clientManager.AddResourceToGroup(clientgroupID, client.Key);
}
}
#region Backgroundworker
///
/// event on Ticker
///
///
///
private void TickSync(object obj, EventArgs e) {
if (!updaterWoker.IsBusy) {
updaterWoker.RunWorkerAsync();
}
}
private void updaterWoker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) {
RefreshForm();
}
private void updaterWoker_DoWork(object sender, DoWorkEventArgs e) {
changes.Clear();
ResponseList jobsOld = jobs;
try {
IJobManager jobManager =
ServiceLocator.GetJobManager();
jobs = jobManager.GetAllJobs();
IDictionary jobsOldHelp;
CloneList(jobsOld, out jobsOldHelp);
if(jobsOld != null && jobsOld.List != null && jobsOldHelp != null)
GetDelta(jobsOld.List, jobsOldHelp);
}
catch (FaultException fe) {
MessageBox.Show(fe.Message);
}
}
#endregion
private void AddClients() {
lvClientGroups = new List();
clientList.Clear();
tvClientControl.Nodes.Clear();
try {
ResponseList clientGroups = ClientManager.GetAllClientGroups();
if (clientGroups != null && clientGroups.List != null) {
foreach (ClientGroupDto cg in clientGroups.List) {
AddClientOrGroup(cg, null);
}
if (currentGroupNode != null) {
lvClientControl.Items.Clear();
lvClientControl.Groups.Clear();
AddGroupsToListView(currentGroupNode);
}
tvClientControl.ExpandAll();
}
}
catch (FaultException fe) {
MessageBox.Show(fe.Message);
}
}
private void AddClientOrGroup(ClientGroupDto clientGroup, TreeNode currentNode) {
currentNode = CreateTreeNode(clientGroup, currentNode);
List clientGroupList = new List();
ListViewGroup lvg;
if (string.IsNullOrEmpty(clientGroup.Name)) {
lvg = new ListViewGroup(NOGROUP, HorizontalAlignment.Left);
} else {
lvg = new ListViewGroup(clientGroup.Name, HorizontalAlignment.Left);
}
lvClientControl.Groups.Add(lvg);
lvg.Tag = clientGroup;
lvClientGroups.Add(lvg);
foreach (ResourceDto resource in clientGroup.Resources) {
if (resource is ClientDto) {
int percentageUsage = CapacityRam(((ClientDto)resource).NrOfCores, ((ClientDto)resource).NrOfFreeCores);
int usage = 3;
if ((((ClientDto)resource).State != State.offline) &&
(((ClientDto)resource).State != State.nullState)) {
if ((percentageUsage >= 0) && (percentageUsage <= 25)) {
usage = 0;
} else if ((percentageUsage > 25) && (percentageUsage <= 75)) {
usage = 1;
} else if ((percentageUsage > 75) && (percentageUsage <= 100)) {
usage = 2;
}
}
ListViewItem lvi = new ListViewItem(resource.Name, usage, lvg);
lvi.Tag = resource as ClientDto;
clientGroupList.Add(lvi);
} else if (resource is ClientGroupDto) {
AddClientOrGroup(resource as ClientGroupDto, currentNode);
}
}
clientList.Add(clientGroup.Id, clientGroupList);
}
private TreeNode CreateTreeNode(ClientGroupDto clientGroup, TreeNode currentNode) {
TreeNode tn;
if (string.IsNullOrEmpty(clientGroup.Name)) {
tn = new TreeNode(NOGROUP);
} else {
tn = new TreeNode(clientGroup.Name);
}
tn.Tag = clientGroup;
if (currentNode == null) {
tvClientControl.Nodes.Add(tn);
} else {
currentNode.Nodes.Add(tn);
}
return tn;
}
private void AddGroupsToListView(TreeNode node) {
if (node != null) {
ListViewGroup lvg = new ListViewGroup(node.Text, HorizontalAlignment.Left);
lvClientControl.Groups.Add(lvg);
lvg.Tag = node.Tag;
foreach (ListViewItem item in clientList[((ClientGroupDto)node.Tag).Id]) {
item.Group = lvg;
lvClientControl.Items.Add(item);
}
if (node.Nodes != null) {
foreach (TreeNode curNode in node.Nodes) {
AddGroupsToListView(curNode);
}
}
}
}
///
/// if one job is clicked, the details for the clicked job are shown
/// in the second panel
///
private void JobClicked() {
plJobDetails.Visible = true;
lvJobDetails.Items.Clear();
ResponseObject response = ServiceLocator.GetJobManager().GetJobByIdWithDetails(currentJob.Id);
if(response.Success == false || response.Obj == null)
return;
JobDto job = response.Obj;
//lvSnapshots.Enabled = true;
if (job.State == State.offline) {
pbJobControl.Image = ilLargeImgJob.Images[2];
} else if (job.State == State.calculating) {
pbJobControl.Image = ilLargeImgJob.Images[1];
} else if (job.State == State.finished) {
pbJobControl.Image = ilLargeImgJob.Images[0];
}
lblJobName.Text = job.Id.ToString();
if (job.Percentage != null) {
progressJob.Value = (int) (currentJob.Percentage*100);
lblProgress.Text = (int) (currentJob.Percentage*100) + "% calculated";
}
ListViewItem lvi = new ListViewItem();
lvi.Text = "User:";
lvi.SubItems.Add(job.UserId.ToString());
lvJobDetails.Items.Add(lvi);
lvi = null;
lvi = new ListViewItem();
lvi.Text = "created at:";
lvi.SubItems.Add(job.DateCreated.ToString());
lvJobDetails.Items.Add(lvi);
if (job.ParentJob != null) {
lvi = null;
lvi = new ListViewItem();
lvi.Text = "Parent job:";
lvi.SubItems.Add(job.ParentJob.ToString());
lvJobDetails.Items.Add(lvi);
}
lvi = null;
lvi = new ListViewItem();
lvi.Text = "Priority:";
lvi.SubItems.Add(job.Priority.ToString());
lvJobDetails.Items.Add(lvi);
if (job.Project != null) {
lvi = null;
lvi = new ListViewItem();
lvi.Text = "Project:";
lvi.SubItems.Add(job.Project.Name.ToString());
lvJobDetails.Items.Add(lvi);
}
if (job.Client != null) {
lvi = null;
lvi = new ListViewItem();
lvi.Text = "Calculation begin:";
lvi.SubItems.Add(job.DateCalculated.ToString());
lvJobDetails.Items.Add(lvi);
lvi = null;
lvi = new ListViewItem();
lvi.Text = "Client calculated:";
lvi.SubItems.Add(job.Client.Name.ToString());
lvJobDetails.Items.Add(lvi);
if (job.State == State.finished) {
lvi = null;
lvi = new ListViewItem();
lvi.Text = "Calculation ended:";
lvi.SubItems.Add(job.DateFinished.ToString());
lvJobDetails.Items.Add(lvi);
}
}
}
///
/// if one client is clicked, the details for the clicked client are shown
/// in the second panel
///
private void ClientClicked() {
plClientDetails.Visible = true;
if (currentClient != null) {
int percentageUsage = CapacityRam(currentClient.NrOfCores, currentClient.NrOfFreeCores);
int usage = 3;
if ((currentClient.State != State.offline) && (currentClient.State != State.nullState)) {
if ((percentageUsage >= 0) && (percentageUsage <= 25)) {
usage = 0;
} else if ((percentageUsage > 25) && (percentageUsage <= 75)) {
usage = 1;
} else if ((percentageUsage > 75) && (percentageUsage <= 100)) {
usage = 2;
}
}
pbClientControl.Image = ilLargeImgClient.Images[usage];
lblClientName.Text = currentClient.Name;
lblLogin.Text = currentClient.Login.ToString();
lblState.Text = currentClient.State.ToString();
}
}
private void RefreshForm() {
foreach (Changes change in changes) {
if (change.Types == Type.Job) {
RefreshJob(change);
}
}
}
private void RefreshJob(Changes change) {
/*if (change.ChangeType == Change.Update) {
for (int i = 0; i < lvJobControl.Items.Count; i++) {
if (lvJobControl.Items[i].Text == change.ID.ToString()) {
foreach (JobDto job in jobs.List) {
if (job.Id == change.ID) {
lvJobControl.Items[i].Tag = job;
if (currentJob != null) {
if (currentJob.Id == change.ID) {
currentJob = job;
JobClicked();
}
}
break;
}
}
State state = jobs.List[change.Position].State;
if (state == State.finished) {
lvJobControl.Items[i].Group = jobGroup[1];
lvJobControl.Items[i].ImageIndex = 0;
} else if (state == State.calculating) {
lvJobControl.Items[i].Group = jobGroup[0];
lvJobControl.Items[i].ImageIndex = 1;
} else if (state == State.offline || state == State.pending) {
lvJobControl.Items[i].Group = jobGroup[2];
lvJobControl.Items[i].ImageIndex = 2;
}
lvJobControl.Refresh();
}
}
} else if (change.ChangeType == Change.Create) {
ListViewItem lvi = new ListViewItem(
change.ID.ToString(), 2, jobGroup[2]);
foreach (JobDto job in jobs.List) {
if (job.Id == change.ID) {
lvi.Tag = job;
break;
}
}
lvJobControl.Items.Add(lvi);
} else if (change.ChangeType == Change.Delete) {
for (int i = 0; i < lvJobControl.Items.Count; i++) {
if (change.ID.ToString() == lvJobControl.Items[i].Text.ToString()) {
lvJobControl.Items[i].Remove();
break;
}
}
} */
}
#region Eventhandlers
///
/// Send event to Login-GUI when closing
///
///
///
private void Close_Click(object sender, EventArgs e) {
if (closeFormEvent != null) {
closeFormEvent(true, false);
}
this.Close();
}
///
/// Send evnt to Login-GUI when closing
///
///
///
private void HiveServerConsoleInformation_FormClosing(object sender, FormClosingEventArgs e) {
if (closeFormEvent != null) {
closeFormEvent(true, false);
}
}
private void AddJob_Click(object sender, EventArgs e) {
AddJobForm newForm = new AddJobForm();
newForm.Show();
newForm.addJobEvent += new addDelegate(updaterWoker.RunWorkerAsync);
}
private void OnLVJobControlClicked(object sender, EventArgs e) {
JobListView jlv = (JobListView) sender;
currentJob = (JobDto)jlv.SelectedItems[0].Tag;
JobClicked();
}
private void lvJobControl_MouseMove(object sender, MouseEventArgs e) {
JobListView jlv = (JobListView) sender;
if ((jlv.GetItemAt(e.X, e.Y) != null) &&
(jlv.GetItemAt(e.X, e.Y).ToolTipText != null)) {
tt.SetToolTip(jlv, jlv.GetItemAt(e.X, e.Y).ToolTipText);
}
}
private void lvJobControl_MouseUp(object sender, MouseEventArgs e) {
// If the right mouse button was clicked and released,
// display the shortcut menu assigned to the ListView.
JobListView jlv = (JobListView)sender;
jlv.ContextMenuStrip.Items.Clear();
ListViewHitTestInfo hitTestInfo = jlv.HitTest(e.Location);
if (e.Button == MouseButtons.Right && hitTestInfo.Item != null && jlv.SelectedItems.Count == 1) {
JobDto selectedJob = (JobDto)jlv.SelectedItems[0].Tag;
if (selectedJob != null && selectedJob.State == State.calculating) {
jlv.ContextMenuStrip.Items.Add(offlineItemAbortJob);
jlv.ContextMenuStrip.Items.Add(menuItemGetSnapshot);
}
}
jlv.ContextMenuStrip.Show(new Point(e.X, e.Y));
}
private void tvClientControl_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) {
lvClientControl.Items.Clear();
lvClientControl.Groups.Clear();
currentGroupNode = e.Node;
AddGroupsToListView(e.Node);
}
private void groupToolStripMenuItem_Click(object sender, EventArgs e) {
AddGroup addgroup = new AddGroup();
parentgroup = Guid.Empty;
if ((tvClientControl.SelectedNode != null) && (((ClientGroupDto)tvClientControl.SelectedNode.Tag).Id != Guid.Empty)) {
parentgroup = ((ClientGroupDto)tvClientControl.SelectedNode.Tag).Id;
}
addgroup.addGroupEvent += new AddGroupDelegate(addgroup_addGroupEvent);
addgroup.Show();
}
private void projectToolStripMenuItem_Click(object sender, EventArgs e) {
AddProject addproject = new AddProject();
addproject.AddProjectEvent += new AddProjectDelegate(addproject_AddProjectEvent);
addproject.Show();
}
private void OnLVClientClicked(object sender, EventArgs e) {
currentClient = (ClientDto)lvClientControl.SelectedItems[0].Tag;
ClientClicked();
}
private void tvClientControl_MouseUp(object sender, MouseEventArgs e) {
// If the right mouse button was clicked and released,
// display the shortcut menu assigned to the ListView.
contextMenuGroup.Items.Clear();
TreeViewHitTestInfo hitTestInfo = tvClientControl.HitTest(e.Location);
tvClientControl.SelectedNode = hitTestInfo.Node;
if (e.Button != MouseButtons.Right) return;
if (hitTestInfo.Node != null) {
ResourceDto selectedGroup = (ResourceDto)tvClientControl.SelectedNode.Tag;
if (selectedGroup != null) {
contextMenuGroup.Items.Add(menuItemAddGroup);
contextMenuGroup.Items.Add(menuItemDeleteGroup);
contextMenuGroup.Items.Add(menuItemOpenCalendar);
}
} else {
contextMenuGroup.Items.Add(menuItemAddGroup);
}
tvClientControl.ContextMenuStrip.Show(tvClientControl, new Point(e.X, e.Y));
}
private void addproject_AddProjectEvent(string name) {
IJobManager jobManager = ServiceLocator.GetJobManager();
ProjectDto pg = new ProjectDto() { Name = name };
jobManager.CreateProject(pg);
}
private void addgroup_addGroupEvent(string name) {
IClientManager clientManager = ServiceLocator.GetClientManager();
if (parentgroup != Guid.Empty) {
ClientGroupDto cg = new ClientGroupDto() { Name = name };
ResponseObject respcg = clientManager.AddClientGroup(cg);
Response res = clientManager.AddResourceToGroup(parentgroup, respcg.Obj);
if (res != null && !res.Success) {
MessageBox.Show(res.StatusMessage, "Error adding Group", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
} else {
ClientGroupDto cg = new ClientGroupDto() { Name = name };
clientManager.AddClientGroup(cg);
}
AddClients();
}
private void Refresh_Click(object sender, EventArgs e) {
Form overlayingForm = new Form();
overlayingForm.Show();
overlayingForm.FormBorderStyle = FormBorderStyle.None;
overlayingForm.BackColor = Color.Gray;
overlayingForm.Opacity = 0.4;
overlayingForm.Size = this.Size;
overlayingForm.Location = this.Location;
AddClients();
overlayingForm.Close();
}
private void largeIconsToolStripMenuItem_Click(object sender, EventArgs e) {
lvClientControl.View = View.LargeIcon;
//lvJobControl.View = View.LargeIcon;
largeIconsToolStripMenuItem.CheckState = CheckState.Checked;
smallIconsToolStripMenuItem.CheckState = CheckState.Unchecked;
listToolStripMenuItem.CheckState = CheckState.Unchecked;
}
private void smallIconsToolStripMenuItem_Click(object sender, EventArgs e) {
lvClientControl.View = View.SmallIcon;
//lvJobControl.View = View.SmallIcon;
largeIconsToolStripMenuItem.CheckState = CheckState.Unchecked;
smallIconsToolStripMenuItem.CheckState = CheckState.Checked;
listToolStripMenuItem.CheckState = CheckState.Unchecked;
}
private void listToolStripMenuItem_Click(object sender, EventArgs e) {
lvClientControl.View = View.List;
//lvJobControl.View = View.List;
largeIconsToolStripMenuItem.CheckState = CheckState.Unchecked;
smallIconsToolStripMenuItem.CheckState = CheckState.Unchecked;
listToolStripMenuItem.CheckState = CheckState.Checked;
}
private void tvClientControl_DragLeave(object sender, EventArgs e) {
foreach (TreeNode node in tvClientControl.Nodes) {
node.BackColor = Color.White;
node.ForeColor = Color.Black;
}
}
#endregion
#region Helper methods
private void CloneList(ResponseList oldList, out IDictionary newList) {
newList = new Dictionary();
if (oldList != null && oldList.List != null) {
for (int i = 0; i < oldList.List.Count; i++) {
newList.Add(i, oldList.List[i]);
}
}
}
private bool IsEqual(ClientDto ci1, ClientDto ci2) {
if (ci1 == null && ci2 == null) {
return true;
}
if (ci2 == null) {
return false;
}
if (ci1.Id.Equals(ci2.Id)) {
return true;
} else return false;
}
private int CapacityRam(int noCores, int freeCores) {
if (noCores > 0) {
int capacity = ((noCores - freeCores) / noCores) * 100;
return capacity;
}
return 100;
}
private void GetDelta(IList oldJobs, IDictionary helpJobs) {
bool found = false;
for (int i = 0; i < jobs.List.Count; i++) {
JobDto job = jobs.List[i];
for (int j = 0; j < oldJobs.Count; j++) {
JobDto jobold = oldJobs[j];
if (job.Id.Equals(jobold.Id)) {
found = true;
bool change = false;
if (job.State != jobold.State) {
change = true;
}
if (job.State != State.offline) {
if ((!IsEqual(job.Client, jobold.Client)) || (job.State != jobold.State)
|| (job.Percentage != jobold.Percentage)) {
change = true;
}
} else if (job.DateCalculated != jobold.DateCalculated) {
change = true;
}
if (change) {
changes.Add(new Changes { Types = Type.Job, ID = job.Id, ChangeType = Change.Update, Position = i });
}
int removeAt = -1;
foreach (KeyValuePair kvp in helpJobs) {
if (job.Id.Equals(kvp.Value.Id)) {
removeAt = kvp.Key;
break;
}
}
if (removeAt >= 0) {
helpJobs.Remove(removeAt);
}
break;
}
}
if (found == false) {
changes.Add(new Changes { Types = Type.Job, ID = job.Id, ChangeType = Change.Create });
}
found = false;
}
foreach (KeyValuePair kvp in helpJobs) {
changes.Add(new Changes { Types = Type.Job, ID = kvp.Value.Id, ChangeType = Change.Delete, Position = kvp.Key });
}
}
#endregion
private void btn_prev_Click(object sender, EventArgs e) {
if (sender == btn_finishedJob_prev)
jdfFinished.Backward();
else if (sender == btn_calculatingJobs_prev)
jdfCalculating.Backward();
else if (sender == btn_offlinejob_prev) {
jdfOffline.Backward();
}
}
private void btn_next_Click(object sender, EventArgs e) {
if (sender == btn_finishedJob_next)
jdfFinished.Forward();
else if (sender == btn_calculatingJobs_next)
jdfCalculating.Forward();
else if (sender == btn_offlineJob_next) {
jdfOffline.Forward();
}
}
private void cmb_count_SelectedIndexChanged(object sender, EventArgs e) {
ComboBox box = (ComboBox) sender;
if (box.SelectedItem != null) {
int val;
if (Int32.TryParse(box.SelectedItem.ToString(), out val)) {
if (box == cmb_offlineJob_count) {
jdfOffline.NrOfEntriesOnPage = val;
}
else if (box == cmb_finishedJob_count) {
jdfFinished.NrOfEntriesOnPage = val;
}
else if (box == cmb_calculatingJob_count) {
jdfCalculating.NrOfEntriesOnPage = val;
}
}
}
}
private void lv_Jobs_SelectedIndexChanged(object sender, EventArgs e) {
ListView lv = (ListView) sender;
if(lv.SelectedItems.Count > 0) {
foreach (ListViewItem lvi in lv.SelectedItems) {
currentJob = (JobDto) lvi.Tag;
JobClicked();
}
}
}
}
}