Changeset 1657 for trunk/sources/HeuristicLab.Hive.Server.Console/3.2/HiveServerManagementConsole.cs
- Timestamp:
- 04/24/09 14:38:15 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Hive.Server.Console/3.2/HiveServerManagementConsole.cs
r1645 r1657 46 46 47 47 #region private variables 48 private ResponseList<ClientGroup> client s = null;49 private ResponseList<ClientInfo> client Info= null;48 private ResponseList<ClientGroup> clientGroups = null; 49 private ResponseList<ClientInfo> clients = null; 50 50 private ResponseList<Job> jobs = null; 51 51 … … 67 67 68 68 private ToolTip tt = new ToolTip(); 69 70 private const string NOGROUP = "No group"; 71 //private List<ListViewItem> clientList = new List<ListViewItem>(); 72 private Dictionary<Guid, List<ListViewItem>> clientList = new Dictionary<Guid, List<ListViewItem>>(); 69 73 70 74 private IClientManager ClientManager { … … 161 165 162 166 // ListViewGroup lvg = new ListViewGroup(cg.Name, HorizontalAlignment.Left); 163 167 164 168 // foreach (ClientInfo ci in cg.Resources) { 165 169 // ListViewItem item = null; … … 235 239 236 240 private void AddClients() { 237 clients = ClientManager.GetAllClientGroups(); 238 239 foreach (ClientGroup cg in clients.List) { 240 AddClientOrGroup(cg, null); 241 } 241 clientList.Clear(); 242 tvClientControl.Nodes.Clear(); 243 244 clientGroups = ClientManager.GetAllClientGroups(); 245 246 foreach (ClientGroup cg in clientGroups.List) { 247 AddClientOrGroup(cg, null); 248 } 249 250 tvClientControl.ExpandAll(); 242 251 } 243 252 244 253 private void AddClientOrGroup(ClientGroup clientGroup, TreeNode currentNode) { 245 254 currentNode = CreateTreeNode(clientGroup, currentNode); 246 ListViewGroup lvg = new ListViewGroup(clientGroup.Name, HorizontalAlignment.Left); 247 255 List<ListViewItem> clientGroupList = new List<ListViewItem>(); 256 ListViewGroup lvg; 257 if (string.IsNullOrEmpty(clientGroup.Name)) { 258 lvg = new ListViewGroup(NOGROUP, HorizontalAlignment.Left); 259 } else { 260 lvg = new ListViewGroup(clientGroup.Name, HorizontalAlignment.Left); 261 } 262 lvClientControl.Groups.Add(lvg); 248 263 foreach (Resource resource in clientGroup.Resources) { 249 264 if (resource is ClientInfo) { 250 265 ListViewItem lvi = new ListViewItem(resource.Name, 0, lvg); 251 266 lvi.Tag = resource as ClientInfo; 252 // has to be added to lvClientControl, not group 253 lvClientControl.Items.Add(lvi); 267 clientGroupList.Add(lvi); 254 268 } else if (resource is ClientGroup) { 255 269 AddClientOrGroup(resource as ClientGroup, currentNode); 256 270 } 257 271 } 258 if (lvg.Items.Count > 0) { 259 lvClientControl.Groups.Add(lvg); 260 } 272 clientList.Add(clientGroup.Id, clientGroupList); 261 273 } 262 274 263 275 private TreeNode CreateTreeNode(ClientGroup clientGroup, TreeNode currentNode) { 264 265 if (string.IsNullOrEmpty(clientGroup.Name)) {266 tn = new TreeNode("No group");276 TreeNode tn; 277 if (string.IsNullOrEmpty(clientGroup.Name)) { 278 tn = new TreeNode(NOGROUP); 267 279 } else { 268 280 tn = new TreeNode(clientGroup.Name); 269 281 } 270 282 tn.Tag = clientGroup; … … 302 314 foreach (Job job in jobs.List) { 303 315 if (job.State == State.calculating) { 304 ListViewItem lvi = new ListViewItem(job.Id.ToString(), 0, lvJobCalculating);316 ListViewItem lvi = new ListViewItem(job.Id.ToString(), 1, lvJobCalculating); 305 317 lvi.Tag = job; 306 318 jobObjects.Add(job.Id, lvi); … … 310 322 lvi.ToolTipText = (job.Percentage * 100) + "% of job calculated"; 311 323 } else if (job.State == State.finished) { 312 ListViewItem lvi = new ListViewItem(job.Id.ToString(), 324 ListViewItem lvi = new ListViewItem(job.Id.ToString(),0, lvJobFinished); 313 325 lvi.Tag = job; 314 326 jobObjects.Add(job.Id, lvi); 315 327 //lvJobControl.Items.Add(lvi); 316 328 } else if (job.State == State.offline) { 317 ListViewItem lvi = new ListViewItem(job.Id.ToString(), 0, lvJobPending);329 ListViewItem lvi = new ListViewItem(job.Id.ToString(), 2, lvJobPending); 318 330 lvi.Tag = job; 319 331 jobObjects.Add(job.Id, lvi); … … 345 357 private void ClientClicked() { 346 358 plClientDetails.Visible = true; 347 int i = 0; 348 while (clientInfo.List[i].Id.ToString() != nameCurrentClient) { 349 i++; 350 } 351 currentClient = clientInfo.List[i]; 359 //int i = 0; 360 //while (clientInfo.List[i].Id.ToString() != nameCurrentClient) { 361 // i++; 362 //} 363 if (lvClientControl.SelectedItems != null && lvClientControl.SelectedItems.Count > 0) { 364 currentClient = (ClientInfo)lvClientControl.SelectedItems[0].Tag; 365 } 366 if(currentClient != null) { 352 367 int percentageUsage = CapacityRam(currentClient.NrOfCores, currentClient.NrOfFreeCores); 353 368 int usage = 3; … … 365 380 lblLogin.Text = currentClient.Login.ToString(); 366 381 lblState.Text = currentClient.State.ToString(); 382 } 367 383 } 368 384 … … 421 437 RefreshJob(change); 422 438 } else if (change.Types == Type.Client) { 423 RefreshClient(change);439 //RefreshClient(change); 424 440 } else if (change.Types == Type.ClientGroup) { 425 RefreshClientGroup(change);441 //RefreshClientGroup(change); 426 442 } 427 443 } … … 475 491 ClientClicked(); 476 492 } 477 State state = client Info.List[change.Position].State;493 State state = clients.List[change.Position].State; 478 494 System.Diagnostics.Debug.WriteLine(lvClientControl.Items[i].Text.ToString()); 479 495 480 496 ClientInfo ci = null; 481 497 482 foreach (ClientInfo c in client Info.List) {498 foreach (ClientInfo c in clients.List) { 483 499 if (c.Id == change.ID) { 484 500 ci = c; … … 574 590 575 591 changes.Clear(); 576 IClientManager clientManager = 577 ServiceLocator.GetClientManager(); 578 579 #region ClientInfo 580 ResponseList<ClientInfo> clientInfoOld = clientInfo; 581 clientInfo = clientManager.GetAllClients(); 582 583 IDictionary<int, ClientInfo> clientInfoOldHelp; 584 585 CloneList(clientInfoOld, out clientInfoOldHelp); 586 587 GetDelta(clientInfoOld.List, clientInfoOldHelp); 588 #endregion 592 593 //#region ClientInfo 594 //ResponseList<ClientInfo> clientInfoOld = clientInfo; 595 //clientInfo = ClientManager.GetAllClients(); 596 597 //IDictionary<int, ClientInfo> clientInfoOldHelp; 598 599 //CloneList(clientInfoOld, out clientInfoOldHelp); 600 601 //GetDelta(clientInfoOld.List, clientInfoOldHelp); 602 //#endregion 589 603 590 604 #region Clients 591 ResponseList<ClientGroup> clientsOld = clients; 592 593 clients = clientManager.GetAllClientGroups(); 594 595 IDictionary<int, ClientGroup> clientsOldHelp; 596 597 CloneList(clientsOld, out clientsOldHelp); 598 599 GetDelta(clientsOld.List, clientsOldHelp); 605 //ResponseList<ClientGroup> clientsOld = clients; 606 607 // newClients = ClientManager.GetAllClientGroups(); 608 609 //IDictionary<Guid, ClientGroup> clientsOldHelp; 610 611 //CloneList(clientsOld, out clientsOldHelp); 612 613 //GetDelta(clientsOld.List, clientsOldHelp); 614 //DetermineDelta(); 600 615 #endregion 601 616 … … 630 645 } 631 646 632 private void CloneList(ResponseList<ClientInfo> oldList, out IDictionary<int, ClientInfo> newList) {633 newList = new Dictionary<int, ClientInfo>();634 for (int i = 0; i < oldList.List.Count; i++) {635 newList.Add(i, oldList.List[i]);636 }637 }638 639 private void CloneList(ResponseList<ClientGroup> oldList, out IDictionary< int, ClientGroup> newList) {640 newList = new Dictionary< int, ClientGroup>();641 for (int i = 0; i < oldList.List.Count; i++) {642 newList.Add( i, oldList.List[i]);647 //private void CloneList(ResponseList<ClientInfo> oldList, out IDictionary<int, ClientInfo> newList) { 648 // newList = new Dictionary<int, ClientInfo>(); 649 // for (int i = 0; i < oldList.List.Count; i++) { 650 // newList.Add(i, oldList.List[i]); 651 // } 652 //} 653 654 private void CloneList(ResponseList<ClientGroup> oldList, out IDictionary<Guid, ClientGroup> newList) { 655 newList = new Dictionary<Guid, ClientGroup>(); 656 foreach (ClientGroup clientGroup in oldList.List) { 657 newList.Add(clientGroup.Id, clientGroup); 643 658 } 644 659 } … … 654 669 655 670 private int CapacityRam(int noCores, int freeCores) { 656 int capacity = ((noCores - freeCores) / noCores) * 100; 657 System.Diagnostics.Debug.WriteLine(capacity); 658 return capacity; 659 } 660 661 private void GetDelta(IList<ClientInfo> oldClient, IDictionary<int, ClientInfo> helpClients) { 662 bool found = false; 663 664 for (int i = 0; i < clientInfo.List.Count; i++) { 665 ClientInfo ci = clientInfo.List[i]; 666 for (int j = 0; j < oldClient.Count; j++) { 667 ClientInfo cio = oldClient[j]; 668 if (ci.Id.Equals(cio.Id)) { 669 found = true; 670 if ((ci.State != cio.State) || (ci.NrOfFreeCores != cio.NrOfFreeCores)) { 671 changes.Add(new Changes { Types = Type.Client, ID = ci.Id, ChangeType = Change.Update, Position = i }); 672 } 673 int removeAt = -1; 674 foreach (KeyValuePair<int, ClientInfo> kvp in helpClients) { 675 if (cio.Id.Equals(kvp.Value.Id)) { 676 removeAt = kvp.Key; 677 break; 678 } 679 } 680 if (removeAt >= 0) { 681 helpClients.Remove(removeAt); 682 } 683 break; 684 } 685 } 686 if (found == false) { 687 changes.Add(new Changes { Types = Type.Client, ID = ci.Id, ChangeType = Change.Create }); 688 } 689 found = false; 690 } 691 foreach (KeyValuePair<int, ClientInfo> kvp in helpClients) { 692 changes.Add(new Changes { Types = Type.Client, ID = kvp.Value.Id, ChangeType = Change.Delete, Position = kvp.Key }); 693 } 694 695 } 696 697 private void GetDelta(IList<ClientGroup> oldClient, IDictionary<int, ClientGroup> helpClients) { 698 699 bool found = false; 700 for (int i = 0; i < clients.List.Count; i++) { 701 ClientGroup cg = clients.List[i]; 702 for (int j = 0; j < oldClient.Count; i++) { 703 ClientGroup cgo = oldClient[j]; 704 if (cg.Id.Equals(cgo.Id)) { 705 found = true; 706 foreach (Resource resource in cg.Resources) { 707 foreach (Resource resourceold in cgo.Resources) { 708 if (resource.Id.Equals(resourceold.Id)) { 709 if (resourceold.Name != resource.Name) { 710 changes.Add(new Changes { Types = Type.Client, ID = cg.Id, ChangeType = Change.Update, Position = i }); 711 } 712 } 713 } 714 } 715 for (int k = 0; k < helpClients.Count; k++) { 716 if (cgo.Id.Equals(helpClients[k].Id)) { 717 helpClients.Remove(k); 718 break; 719 } 720 } 721 break; 722 } 723 } 724 if (found == false) { 725 changes.Add(new Changes { Types = Type.ClientGroup, ID = cg.Id, ChangeType = Change.Create }); 726 } 727 found = false; 728 } 729 foreach (KeyValuePair<int, ClientGroup> kvp in helpClients) { 730 changes.Add(new Changes { Types = Type.ClientGroup, ID = kvp.Value.Id, ChangeType = Change.Delete, Position = kvp.Key }); 731 } 732 } 671 if (noCores > 0) { 672 int capacity = ((noCores - freeCores) / noCores) * 100; 673 System.Diagnostics.Debug.WriteLine(capacity); 674 return capacity; 675 } 676 return 100; 677 } 678 679 //private void GetDelta(IList<ClientInfo> oldClient, IDictionary<int, ClientInfo> helpClients) { 680 // bool found = false; 681 682 // for (int i = 0; i < clientInfo.List.Count; i++) { 683 // ClientInfo ci = clientInfo.List[i]; 684 // for (int j = 0; j < oldClient.Count; j++) { 685 // ClientInfo cio = oldClient[j]; 686 // if (ci.Id.Equals(cio.Id)) { 687 // found = true; 688 // if ((ci.State != cio.State) || (ci.NrOfFreeCores != cio.NrOfFreeCores)) { 689 // changes.Add(new Changes { Types = Type.Client, ID = ci.Id, ChangeType = Change.Update, Position = i }); 690 // } 691 // int removeAt = -1; 692 // foreach (KeyValuePair<int, ClientInfo> kvp in helpClients) { 693 // if (cio.Id.Equals(kvp.Value.Id)) { 694 // removeAt = kvp.Key; 695 // break; 696 // } 697 // } 698 // if (removeAt >= 0) { 699 // helpClients.Remove(removeAt); 700 // } 701 // break; 702 // } 703 // } 704 // if (found == false) { 705 // changes.Add(new Changes { Types = Type.Client, ID = ci.Id, ChangeType = Change.Create }); 706 // } 707 // found = false; 708 // } 709 // foreach (KeyValuePair<int, ClientInfo> kvp in helpClients) { 710 // changes.Add(new Changes { Types = Type.Client, ID = kvp.Value.Id, ChangeType = Change.Delete, Position = kvp.Key }); 711 // } 712 713 //} 714 715 private void DetermineDelta() { 716 717 718 719 } 720 721 722 //private void GetDelta(IList<ClientGroup> oldClient, IDictionary<Guid, ClientGroup> helpClients) { 723 724 // bool found = false; 725 // for (int i = 0; i < clients.List.Count; i++) { 726 // ClientGroup cg = clientGroups.List[i]; 727 // for (int j = 0; j < oldClient.Count; i++) { 728 // ClientGroup cgo = oldClient[j]; 729 // if (cg.Id.Equals(cgo.Id)) { 730 // found = true; 731 // foreach (Resource resource in cg.Resources) { 732 // foreach (Resource resourceold in cgo.Resources) { 733 // if (resource.Id.Equals(resourceold.Id)) { 734 // if (resourceold.Name != resource.Name) { 735 // changes.Add(new Changes { Types = Type.Client, ID = cg.Id, ChangeType = Change.Update, Position = i }); 736 // } 737 // } 738 // } 739 // } 740 // for (int k = 0; k < helpClients.Count; k++) { 741 // if (cgo.Id.Equals(helpClients[k].Id)) { 742 // helpClients.Remove(k); 743 // break; 744 // } 745 // } 746 // break; 747 // } 748 // } 749 // if (found == false) { 750 // changes.Add(new Changes { Types = Type.ClientGroup, ID = cg.Id, ChangeType = Change.Create }); 751 // } 752 // found = false; 753 // } 754 // foreach (KeyValuePair<int, ClientGroup> kvp in helpClients) { 755 // changes.Add(new Changes { Types = Type.ClientGroup, ID = kvp.Value.Id, ChangeType = Change.Delete, Position = kvp.Key }); 756 // } 757 //} 733 758 734 759 private void GetDelta(IList<Job> oldJobs, IDictionary<int, Job> helpJobs) { … … 820 845 } 821 846 822 823 824 847 private void tvClientControl_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) { 848 lvClientControl.Items.Clear(); 849 lvClientControl.Groups.Clear(); 850 AddGroupsToListView(e.Node); 851 } 852 853 private void AddGroupsToListView(TreeNode node) { 854 if (node != null) { 855 ListViewGroup lvg = new ListViewGroup(node.Text, HorizontalAlignment.Left); 856 lvClientControl.Groups.Add(lvg); 857 foreach (ListViewItem item in clientList[((ClientGroup)node.Tag).Id]) { 858 item.Group = lvg; 859 lvClientControl.Items.Add(item); 860 } 861 862 if (node.Nodes != null) { 863 foreach (TreeNode curNode in node.Nodes) { 864 AddGroupsToListView(curNode); 865 } 866 } 867 } 868 } 869 870 private void refreshToolStripMenuItem_Click(object sender, EventArgs e) { 871 AddClients(); 872 } 825 873 } 826 874 }
Note: See TracChangeset
for help on using the changeset viewer.