Changeset 1937 for trunk/sources/HeuristicLab.Hive.Server.Console/3.2/HiveServerManagementConsole.cs
- Timestamp:
- 05/28/09 17:33:37 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Hive.Server.Console/3.2/HiveServerManagementConsole.cs
r1832 r1937 47 47 48 48 #region private variables 49 private ResponseList<ClientGroup> clientGroups = null;50 private ResponseList<ClientInfo> clients = null;51 49 private ResponseList<Job> jobs = null; 52 50 53 //TODO delete 54 private Dictionary<Guid, ListViewGroup> clientObjects; 55 private Dictionary<Guid, ListViewItem> clientInfoObjects; 56 private Dictionary<Guid, ListViewItem> jobObjects; 51 List<ListViewGroup> jobGroup; 52 private Dictionary<Guid, List<ListViewItem>> clientList = new Dictionary<Guid, List<ListViewItem>>(); 53 private List<Changes> changes = new List<Changes>(); 57 54 58 55 private Job currentJob = null; 59 56 private ClientInfo currentClient = null; 60 57 61 TreeNode currentNode = null; 62 63 //TODO delete 64 private string nameCurrentJob = ""; 65 private string nameCurrentClient = ""; 66 private bool flagJob = false; 67 68 private List<Changes> changes = new List<Changes>(); 69 58 private TreeNode currentNode = null; 59 Guid parentgroup = Guid.Empty; 70 60 private ToolTip tt = new ToolTip(); 71 61 72 62 private const string NOGROUP = "No group"; 73 //private List<ListViewItem> clientList = new List<ListViewItem>(); 74 private Dictionary<Guid, List<ListViewItem>> clientList = new Dictionary<Guid, List<ListViewItem>>(); 75 63 64 #endregion 65 66 #region Properties 76 67 private IClientManager ClientManager { 77 68 get { 78 69 return ServiceLocator.GetClientManager(); 79 70 } 80 81 71 } 82 72 #endregion … … 90 80 } 91 81 82 private void Init() { 83 84 //adding context menu items for jobs 85 menuItemAbortJob.Click += (s, e) => { 86 IJobManager jobManager = ServiceLocator.GetJobManager(); 87 if (lvJobControl.SelectedItems.Count == 1) { 88 jobManager.AbortJob(((Job)(lvJobControl.SelectedItems[0].Tag)).Id); 89 } 90 }; 91 92 //adding context menu items for jobs 93 menuItemGetSnapshot.Click += (s, e) => { 94 IJobManager jobManager = ServiceLocator.GetJobManager(); 95 if (lvJobControl.SelectedItems.Count == 1) { 96 jobManager.RequestSnapshot(((Job)(lvJobControl.SelectedItems[0].Tag)).Id); 97 } 98 }; 99 100 //adding group 101 menuItemAddGroup.Click += (s, e) => { 102 AddGroup addgroup = new AddGroup(); 103 parentgroup = Guid.Empty; 104 if ((tvClientControl.SelectedNode != null) && (((ClientGroup)tvClientControl.SelectedNode.Tag).Id != Guid.Empty)) { 105 parentgroup = ((ClientGroup)tvClientControl.SelectedNode.Tag).Id; 106 } 107 addgroup.addGroupEvent += new AddGroupDelegate(addgroup_addGroupEvent); 108 addgroup.Show(); 109 }; 110 111 //adding group 112 menuItemDeleteGroup.Click += (s, e) => { 113 IClientManager clientManager = ServiceLocator.GetClientManager(); 114 if (tvClientControl.SelectedNode != null) { 115 // Delete Group 116 } 117 }; 118 } 92 119 93 120 #region Backgroundworker … … 104 131 105 132 private void updaterWoker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { 106 Refresh(); 107 } 108 133 RefreshForm(); 134 } 135 136 private void updaterWoker_DoWork(object sender, DoWorkEventArgs e) { 137 138 changes.Clear(); 139 140 //#region ClientInfo 141 //ResponseList<ClientInfo> clientInfoOld = clientInfo; 142 //clientInfo = ClientManager.GetAllClients(); 143 144 //IDictionary<int, ClientInfo> clientInfoOldHelp; 145 146 //CloneList(clientInfoOld, out clientInfoOldHelp); 147 148 //GetDelta(clientInfoOld.List, clientInfoOldHelp); 149 //#endregion 150 151 #region Clients 152 //ResponseList<ClientGroup> clientsOld = clients; 153 154 // newClients = ClientManager.GetAllClientGroups(); 155 156 //IDictionary<Guid, ClientGroup> clientsOldHelp; 157 158 //CloneList(clientsOld, out clientsOldHelp); 159 160 //GetDelta(clientsOld.List, clientsOldHelp); 161 //DetermineDelta(); 162 #endregion 163 164 #region Job 165 ResponseList<Job> jobsOld = jobs; 166 IJobManager jobManager = 167 ServiceLocator.GetJobManager(); 168 169 jobs = jobManager.GetAllJobs(); 170 171 IDictionary<int, Job> jobsOldHelp; 172 CloneList(jobsOld, out jobsOldHelp); 173 174 GetDelta(jobsOld.List, jobsOldHelp); 175 176 #endregion 177 178 foreach (Changes change in changes) { 179 System.Diagnostics.Debug.WriteLine(change.ID + " " + change.ChangeType); 180 } 181 182 } 183 109 184 #endregion 110 185 111 private Guid ConvertStringToGuid(string stringGuid) { 112 return new Guid(stringGuid); 113 } 114 115 116 private void Init() { 117 118 //adding context menu items for jobs 119 menuItemAbortJob.Click += (s, e) => { 120 IJobManager jobManager = ServiceLocator.GetJobManager(); 121 if (lvJobControl.SelectedItems.Count == 1) { 122 jobManager.AbortJob(((Job)(lvJobControl.SelectedItems[0].Tag)).Id); 123 } 124 }; 125 126 //adding context menu items for jobs 127 menuItemGetSnapshot.Click += (s, e) => { 128 IJobManager jobManager = ServiceLocator.GetJobManager(); 129 if (lvJobControl.SelectedItems.Count == 1) { 130 jobManager.RequestSnapshot(((Job)(lvJobControl.SelectedItems[0].Tag)).Id); 131 } 132 }; 133 134 //adding group 135 menuItemAddGroup.Click += (s, e) => { 136 AddGroup addgroup = new AddGroup(); 137 parentgroup = Guid.Empty; 138 if ((tvClientControl.SelectedNode != null) && (((ClientGroup)tvClientControl.SelectedNode.Tag).Id != Guid.Empty)) { 139 parentgroup = ((ClientGroup)tvClientControl.SelectedNode.Tag).Id; 140 } 141 addgroup.addGroupEvent += new AddGroupDelegate(addgroup_addGroupEvent); 142 addgroup.Show(); 143 }; 144 145 //adding group 146 menuItemDeleteGroup.Click += (s, e) => { 147 IClientManager clientManager = ServiceLocator.GetClientManager(); 148 if (tvClientControl.SelectedNode != null) { 149 // Delete Group 150 } 151 }; 152 } 153 154 Guid parentgroup = Guid.Empty; 155 156 void addgroup_addGroupEvent(string name) { 157 IClientManager clientManager = ServiceLocator.GetClientManager(); 158 159 if (parentgroup != Guid.Empty) { 160 ClientGroup cg = new ClientGroup() { Name = name }; 161 ResponseObject<ClientGroup> respcg = clientManager.AddClientGroup(cg); 162 Response res = clientManager.AddResourceToGroup(parentgroup, respcg.Obj); 163 if (res != null && !res.Success) { 164 MessageBox.Show(res.StatusMessage, "Error adding Group", MessageBoxButtons.OK, MessageBoxIcon.Error); 165 } 166 } else { 167 ClientGroup cg = new ClientGroup() { Name = name }; 168 clientManager.AddClientGroup(cg); 169 } 170 171 } 172 173 private void lvJobControl_MouseUp(object sender, MouseEventArgs e) { 174 // If the right mouse button was clicked and released, 175 // display the shortcut menu assigned to the ListView. 176 lvJobControl.ContextMenuStrip.Items.Clear(); 177 ListViewHitTestInfo hitTestInfo = lvJobControl.HitTest(e.Location); 178 if (e.Button == MouseButtons.Right && hitTestInfo.Item != null && lvJobControl.SelectedItems.Count == 1) { 179 Job selectedJob = (Job)lvJobControl.SelectedItems[0].Tag; 180 181 if (selectedJob != null && selectedJob.State == State.calculating) { 182 lvJobControl.ContextMenuStrip.Items.Add(menuItemAbortJob); 183 lvJobControl.ContextMenuStrip.Items.Add(menuItemGetSnapshot); 184 } 185 } 186 lvJobControl.ContextMenuStrip.Show(new Point(e.X, e.Y)); 186 187 /// <summary> 188 /// Adds jobs to ListView and TreeView 189 /// </summary> 190 private void AddJobs() { 191 try { 192 List<ListViewItem> jobObjects = new List<ListViewItem>(); 193 IJobManager jobManager = 194 ServiceLocator.GetJobManager(); 195 jobs = jobManager.GetAllJobs(); 196 197 lvJobControl.Items.Clear(); 198 199 ListViewGroup lvJobCalculating = new ListViewGroup("calculating", HorizontalAlignment.Left); 200 ListViewGroup lvJobFinished = new ListViewGroup("finished", HorizontalAlignment.Left); 201 ListViewGroup lvJobPending = new ListViewGroup("pending", HorizontalAlignment.Left); 202 203 jobGroup = new List<ListViewGroup>(); 204 jobGroup.Add(lvJobCalculating); 205 jobGroup.Add(lvJobFinished); 206 jobGroup.Add(lvJobPending); 207 208 foreach (Job job in jobs.List) { 209 if (job.State == State.calculating) { 210 ListViewItem lvi = new ListViewItem(job.Id.ToString(), 1, lvJobCalculating); 211 lvi.Tag = job; 212 jobObjects.Add(lvi); 213 214 lvi.ToolTipText = (job.Percentage * 100) + "% of job calculated"; 215 } else if (job.State == State.finished) { 216 ListViewItem lvi = new ListViewItem(job.Id.ToString(), 0, lvJobFinished); 217 lvi.Tag = job; 218 jobObjects.Add(lvi); 219 //lvJobControl.Items.Add(lvi); 220 } else if (job.State == State.offline) { 221 ListViewItem lvi = new ListViewItem(job.Id.ToString(), 2, lvJobPending); 222 lvi.Tag = job; 223 jobObjects.Add(lvi); 224 } 225 } // Jobs 226 lvJobControl.BeginUpdate(); 227 foreach (ListViewItem lvi in jobObjects) { 228 lvJobControl.Items.Add(lvi); 229 } 230 // actualization 231 lvJobControl.Groups.Add(lvJobCalculating); 232 lvJobControl.Groups.Add(lvJobFinished); 233 lvJobControl.Groups.Add(lvJobPending); 234 lvJobControl.EndUpdate(); 235 236 if (currentJob != null) { 237 JobClicked(); 238 } 239 } 240 catch (Exception ex) { 241 closeFormEvent(true, true); 242 this.Close(); 243 } 187 244 } 188 245 … … 191 248 tvClientControl.Nodes.Clear(); 192 249 193 clientGroups = ClientManager.GetAllClientGroups();250 ResponseList<ClientGroup> clientGroups = ClientManager.GetAllClientGroups(); 194 251 195 252 foreach (ClientGroup cg in clientGroups.List) { … … 204 261 tvClientControl.ExpandAll(); 205 262 } 206 207 263 208 264 private void AddClientOrGroup(ClientGroup clientGroup, TreeNode currentNode) { … … 256 312 } 257 313 258 259 List<ListViewGroup> jobGroup; 314 private void AddGroupsToListView(TreeNode node) { 315 if (node != null) { 316 ListViewGroup lvg = new ListViewGroup(node.Text, HorizontalAlignment.Left); 317 lvClientControl.Groups.Add(lvg); 318 foreach (ListViewItem item in clientList[((ClientGroup)node.Tag).Id]) { 319 item.Group = lvg; 320 lvClientControl.Items.Add(item); 321 } 322 323 if (node.Nodes != null) { 324 foreach (TreeNode curNode in node.Nodes) { 325 AddGroupsToListView(curNode); 326 } 327 } 328 } 329 } 330 260 331 /// <summary> 261 /// Adds jobs to ListView and TreeView 332 /// if one job is clicked, the details for the clicked job are shown 333 /// in the second panel 262 334 /// </summary> 263 private void AddJobs() { 264 try { 265 jobObjects = new Dictionary<Guid, ListViewItem>(); 266 IJobManager jobManager = 267 ServiceLocator.GetJobManager(); 268 jobs = jobManager.GetAllJobs(); 269 270 lvJobControl.Items.Clear(); 271 272 ListViewGroup lvJobCalculating = new ListViewGroup("calculating", HorizontalAlignment.Left); 273 ListViewGroup lvJobFinished = new ListViewGroup("finished", HorizontalAlignment.Left); 274 ListViewGroup lvJobPending = new ListViewGroup("pending", HorizontalAlignment.Left); 275 276 jobGroup = new List<ListViewGroup>(); 277 jobGroup.Add(lvJobCalculating); 278 jobGroup.Add(lvJobFinished); 279 jobGroup.Add(lvJobPending); 280 281 foreach (Job job in jobs.List) { 282 if (job.State == State.calculating) { 283 ListViewItem lvi = new ListViewItem(job.Id.ToString(), 1, lvJobCalculating); 284 lvi.Tag = job; 285 jobObjects.Add(job.Id, lvi); 286 287 //lvJobControl.Items.Add(lvi); 288 289 lvi.ToolTipText = (job.Percentage * 100) + "% of job calculated"; 290 } else if (job.State == State.finished) { 291 ListViewItem lvi = new ListViewItem(job.Id.ToString(), 0, lvJobFinished); 292 lvi.Tag = job; 293 jobObjects.Add(job.Id, lvi); 294 //lvJobControl.Items.Add(lvi); 295 } else if (job.State == State.offline) { 296 ListViewItem lvi = new ListViewItem(job.Id.ToString(), 2, lvJobPending); 297 lvi.Tag = job; 298 jobObjects.Add(job.Id, lvi); 299 //lvJobControl.Items.Add(lvi); 300 } 301 } // Jobs 302 lvJobControl.BeginUpdate(); 303 foreach (ListViewItem lvi in jobObjects.Values) { 304 lvJobControl.Items.Add(lvi); 305 } 306 lvJobControl.Groups.Add(lvJobCalculating); 307 lvJobControl.Groups.Add(lvJobFinished); 308 lvJobControl.Groups.Add(lvJobPending); 309 lvJobControl.EndUpdate(); 310 if (flagJob) { 311 JobClicked(); 312 } 313 } 314 catch (Exception ex) { 315 closeFormEvent(true, true); 316 this.Close(); 335 private void JobClicked() { 336 plJobDetails.Visible = true; 337 lvJobDetails.Items.Clear(); 338 339 lvSnapshots.Enabled = true; 340 341 if (currentJob.State == State.offline) { 342 pbJobControl.Image = ilLargeImgJob.Images[2]; 343 } else if (currentJob.State == State.calculating) { 344 pbJobControl.Image = ilLargeImgJob.Images[1]; 345 } else if (currentJob.State == State.finished) { 346 pbJobControl.Image = ilLargeImgJob.Images[0]; 347 } 348 349 lblJobName.Text = currentJob.Id.ToString(); 350 progressJob.Value = (int)(currentJob.Percentage * 100); 351 lblProgress.Text = (int)(currentJob.Percentage * 100) + "% calculated"; 352 353 ListViewItem lvi = new ListViewItem(); 354 lvi.Text = "User:"; 355 lvi.SubItems.Add(currentJob.UserId.ToString()); 356 lvJobDetails.Items.Add(lvi); 357 358 lvi = null; 359 lvi = new ListViewItem(); 360 lvi.Text = "created at:"; 361 lvi.SubItems.Add(currentJob.DateCreated.ToString()); 362 lvJobDetails.Items.Add(lvi); 363 364 if (currentJob.ParentJob != null) { 365 lvi = null; 366 lvi = new ListViewItem(); 367 lvi.Text = "Parent job:"; 368 lvi.SubItems.Add(currentJob.ParentJob.ToString()); 369 lvJobDetails.Items.Add(lvi); 370 } 371 372 lvi = null; 373 lvi = new ListViewItem(); 374 lvi.Text = "Priority:"; 375 lvi.SubItems.Add(currentJob.Priority.ToString()); 376 lvJobDetails.Items.Add(lvi); 377 378 if (currentJob.Client != null) { 379 lvi = null; 380 lvi = new ListViewItem(); 381 lvi.Text = "Calculation begin:"; 382 lvi.SubItems.Add(currentJob.DateCalculated.ToString()); 383 lvJobDetails.Items.Add(lvi); 384 385 386 lvi = null; 387 lvi = new ListViewItem(); 388 lvi.Text = "Client calculated:"; 389 lvi.SubItems.Add(currentJob.Client.Name.ToString()); 390 lvJobDetails.Items.Add(lvi); 391 392 if (currentJob.State == State.finished) { 393 IJobManager jobManager = 394 ServiceLocator.GetJobManager(); 395 ResponseObject<JobResult> jobRes = jobManager.GetLastJobResultOf(currentJob.Id, false); 396 397 lvi = null; 398 lvi = new ListViewItem(); 399 lvi.Text = "Calculation ended:"; 400 lvi.SubItems.Add(jobRes.Obj.DateFinished.ToString()); 401 lvJobDetails.Items.Add(lvi); 402 } 403 } 404 if (currentJob.State != State.offline) { 405 lvSnapshots.Items.Clear(); 406 GetSnapshotList(); 407 } else { 408 lvSnapshots.Visible = false; 317 409 } 318 410 } … … 324 416 private void ClientClicked() { 325 417 plClientDetails.Visible = true; 326 //int i = 0; 327 //while (clientInfo.List[i].Id.ToString() != nameCurrentClient) { 328 // i++; 329 //} 330 if (lvClientControl.SelectedItems != null && lvClientControl.SelectedItems.Count > 0) { 331 currentClient = (ClientInfo)lvClientControl.SelectedItems[0].Tag; 332 } 418 333 419 if (currentClient != null) { 334 420 int percentageUsage = CapacityRam(currentClient.NrOfCores, currentClient.NrOfFreeCores); … … 349 435 } 350 436 } 351 352 /// <summary> 353 /// if one job is clicked, the details for the clicked job are shown 354 /// in the second panel 355 /// </summary> 356 private void JobClicked() { 357 plJobDetails.Visible = true; 358 lvJobDetails.Items.Clear(); 359 int i = 0; 360 while (jobs.List[i].Id.ToString() != nameCurrentJob) { 361 i++; 362 } 363 lvSnapshots.Enabled = true; 364 currentJob = jobs.List[i]; 365 if (currentJob.State == State.offline) { 366 pbJobControl.Image = ilLargeImgJob.Images[2]; 367 } else if (currentJob.State == State.calculating) { 368 pbJobControl.Image = ilLargeImgJob.Images[1]; 369 } else if (currentJob.State == State.finished) { 370 pbJobControl.Image = ilLargeImgJob.Images[0]; 371 } 372 373 374 375 lblJobName.Text = currentJob.Id.ToString(); 376 progressJob.Value = (int)(currentJob.Percentage * 100); 377 lblProgress.Text = (int)(currentJob.Percentage * 100) + "% calculated"; 378 lblUserCreatedJob.Text = currentJob.UserId.ToString() + /* currentJob.User.Name + */ " created Job"; 379 //lblJobCreated.Text = "Created at " + currentJob.DateCreated; 380 ListViewItem lvi = new ListViewItem(); 381 lvi.Text = "User:"; 382 lvi.SubItems.Add(currentJob.UserId.ToString()); 383 lvJobDetails.Items.Add(lvi); 384 385 lvi = null; 386 lvi = new ListViewItem(); 387 lvi.Text = "created at:"; 388 lvi.SubItems.Add(currentJob.DateCreated.ToString()); 389 lvJobDetails.Items.Add(lvi); 390 391 if (currentJob.ParentJob != null) { 392 lvi = null; 393 lvi = new ListViewItem(); 394 lvi.Text = "Parent job:"; 395 lvi.SubItems.Add(currentJob.ParentJob.ToString()); 396 lvJobDetails.Items.Add(lvi); 397 // lblParentJob.Text = currentJob.ParentJob.Id + " is parent job"; 398 }// else { 399 // lblParentJob.Text = ""; 400 //} 401 402 lvi = null; 403 lvi = new ListViewItem(); 404 lvi.Text = "Priority:"; 405 lvi.SubItems.Add(currentJob.Priority.ToString()); 406 lvJobDetails.Items.Add(lvi); 407 408 // lblPriorityJob.Text = "Priority of job is " + currentJob.Priority; 409 if (currentJob.Client != null) { 410 lvi = null; 411 lvi = new ListViewItem(); 412 lvi.Text = "Calculation begin:"; 413 lvi.SubItems.Add(currentJob.DateCalculated.ToString()); 414 lvJobDetails.Items.Add(lvi); 415 416 417 lvi = null; 418 lvi = new ListViewItem(); 419 lvi.Text = "Client calculated:"; 420 lvi.SubItems.Add(currentJob.Client.Name.ToString()); 421 lvJobDetails.Items.Add(lvi); 422 423 //lblClientCalculating.Text = currentJob.Client.Name + " calculated Job"; 424 //lblJobCalculationBegin.Text = "Startet calculation at " + currentJob.DateCalculated; 425 426 if (currentJob.State == State.finished) { 427 IJobManager jobManager = 428 ServiceLocator.GetJobManager(); 429 ResponseObject<JobResult> jobRes = jobManager.GetLastJobResultOf(currentJob.Id, false); 430 431 lvi = null; 432 lvi = new ListViewItem(); 433 lvi.Text = "Calculation ended:"; 434 lvi.SubItems.Add(jobRes.Obj.DateFinished.ToString()); 435 lvJobDetails.Items.Add(lvi); 436 // lblJobCalculationEnd.Text = "Calculation ended at " + jobRes.Obj.DateFinished; 437 } 438 } else { 439 // lblClientCalculating.Text = ""; 440 // lblJobCalculationBegin.Text = ""; 441 // lblJobCalculationEnd.Text = ""; 442 } 443 if (currentJob.State != State.offline) { 444 lvSnapshots.Items.Clear(); 445 //if (currentJob.State == State.finished) 446 GetSnapshotList(); 447 //lvSnapshots.Visible = true; 448 } else { 449 lvSnapshots.Visible = false; 450 } 451 } 452 453 private void Refresh() { 437 438 439 private void RefreshForm() { 454 440 foreach (Changes change in changes) { 455 441 if (change.Types == Type.Job) { 456 442 RefreshJob(change); 457 } else if (change.Types == Type.Client) {458 //RefreshClient(change);459 } else if (change.Types == Type.ClientGroup) {460 //RefreshClientGroup(change);461 443 } 462 444 } … … 467 449 for (int i = 0; i < lvJobControl.Items.Count; i++) { 468 450 if (lvJobControl.Items[i].Text == change.ID.ToString()) { 469 if (nameCurrentJob == change.ID.ToString()) {470 JobClicked();471 }472 451 foreach (Job job in jobs.List) { 473 452 if (job.Id == change.ID) { 474 453 lvJobControl.Items[i].Tag = job; 454 if (currentJob.Id == change.ID) { 455 currentJob = job; 456 JobClicked(); 457 } 475 458 break; 476 459 } … … 496 479 } 497 480 } else if (change.ChangeType == Change.Create) { 481 498 482 ListViewItem lvi = new ListViewItem( 499 483 change.ID.ToString(), 2, jobGroup[2]); 500 jobObjects.Add(change.ID, lvi); 484 foreach (Job job in jobs.List) { 485 if (job.Id == change.ID) { 486 lvi.Tag = job; 487 break; 488 } 489 } 501 490 lvJobControl.Items.Add(lvi); 502 491 503 492 } else if (change.ChangeType == Change.Delete) { 504 jobObjects.Remove(change.ID);505 493 for (int i = 0; i < lvJobControl.Items.Count; i++) { 506 494 if (change.ID.ToString() == lvJobControl.Items[i].Text.ToString()) { … … 512 500 } 513 501 514 private void RefreshClient(Changes change) {515 if (change.ChangeType == Change.Update) {516 for (int i = 0; i < lvClientControl.Items.Count; i++) {517 if (lvClientControl.Items[i].Tag.ToString() == change.ID.ToString()) {518 if (nameCurrentClient == change.ID.ToString()) {519 ClientClicked();520 }521 State state = clients.List[change.Position].State;522 System.Diagnostics.Debug.WriteLine(lvClientControl.Items[i].Text.ToString());523 524 ClientInfo ci = null;525 526 foreach (ClientInfo c in clients.List) {527 if (c.Id == change.ID) {528 ci = c;529 }530 }531 532 int percentageUsage = CapacityRam(ci.NrOfCores, ci.NrOfFreeCores);533 if ((state == State.offline) || (state == State.nullState)) {534 lvClientControl.Items[i].ImageIndex = 3;535 } else {536 if ((percentageUsage >= 0) && (percentageUsage <= 25)) {537 lvClientControl.Items[i].ImageIndex = 0;538 } else if ((percentageUsage > 25) && (percentageUsage <= 75)) {539 lvClientControl.Items[i].ImageIndex = 1;540 } else if ((percentageUsage > 75) && (percentageUsage <= 100)) {541 lvClientControl.Items[i].ImageIndex = 2;542 }543 544 }545 lvClientControl.Refresh();546 }547 }548 549 550 } else if (change.ChangeType == Change.Create) {551 552 } else if (change.ChangeType == Change.Delete) {553 clientInfoObjects.Remove(change.ID);554 for (int i = 0; i < lvClientControl.Items.Count; i++) {555 if (change.ID.ToString() == lvClientControl.Items[i].Text.ToString()) {556 lvClientControl.Items[i].Remove();557 break;558 }559 }560 561 }562 }563 564 private void RefreshClientGroup(Changes change) {565 566 }567 502 568 503 #region Eventhandlers … … 596 531 } 597 532 598 private void OnLVClientClicked(object sender, EventArgs e) {599 nameCurrentClient = lvClientControl.SelectedItems[0].Tag.ToString();600 ClientClicked();601 }602 603 533 private void OnLVJobControlClicked(object sender, EventArgs e) { 604 nameCurrentJob = lvJobControl.SelectedItems[0].Text; 605 flagJob = true; 534 currentJob = (Job)lvJobControl.SelectedItems[0].Tag; 606 535 JobClicked(); 607 536 } … … 614 543 } 615 544 616 private void updaterWoker_DoWork(object sender, DoWorkEventArgs e) { 617 618 changes.Clear(); 619 620 //#region ClientInfo 621 //ResponseList<ClientInfo> clientInfoOld = clientInfo; 622 //clientInfo = ClientManager.GetAllClients(); 623 624 //IDictionary<int, ClientInfo> clientInfoOldHelp; 625 626 //CloneList(clientInfoOld, out clientInfoOldHelp); 627 628 //GetDelta(clientInfoOld.List, clientInfoOldHelp); 629 //#endregion 630 631 #region Clients 632 //ResponseList<ClientGroup> clientsOld = clients; 633 634 // newClients = ClientManager.GetAllClientGroups(); 635 636 //IDictionary<Guid, ClientGroup> clientsOldHelp; 637 638 //CloneList(clientsOld, out clientsOldHelp); 639 640 //GetDelta(clientsOld.List, clientsOldHelp); 641 //DetermineDelta(); 642 #endregion 643 644 #region Job 645 ResponseList<Job> jobsOld = jobs; 646 IJobManager jobManager = 647 ServiceLocator.GetJobManager(); 648 649 jobs = jobManager.GetAllJobs(); 650 651 IDictionary<int, Job> jobsOldHelp; 652 CloneList(jobsOld, out jobsOldHelp); 653 654 GetDelta(jobsOld.List, jobsOldHelp); 655 656 #endregion 657 658 foreach (Changes change in changes) { 659 System.Diagnostics.Debug.WriteLine(change.ID + " " + change.ChangeType); 660 } 661 545 private void lvJobControl_MouseUp(object sender, MouseEventArgs e) { 546 // If the right mouse button was clicked and released, 547 // display the shortcut menu assigned to the ListView. 548 lvJobControl.ContextMenuStrip.Items.Clear(); 549 ListViewHitTestInfo hitTestInfo = lvJobControl.HitTest(e.Location); 550 if (e.Button == MouseButtons.Right && hitTestInfo.Item != null && lvJobControl.SelectedItems.Count == 1) { 551 Job selectedJob = (Job)lvJobControl.SelectedItems[0].Tag; 552 553 if (selectedJob != null && selectedJob.State == State.calculating) { 554 lvJobControl.ContextMenuStrip.Items.Add(menuItemAbortJob); 555 lvJobControl.ContextMenuStrip.Items.Add(menuItemGetSnapshot); 556 } 557 } 558 lvJobControl.ContextMenuStrip.Show(new Point(e.X, e.Y)); 559 } 560 561 private void tvClientControl_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) { 562 lvClientControl.Items.Clear(); 563 lvClientControl.Groups.Clear(); 564 currentNode = e.Node; 565 AddGroupsToListView(e.Node); 566 } 567 568 private void groupToolStripMenuItem_Click(object sender, EventArgs e) { 569 AddGroup addgroup = new AddGroup(); 570 parentgroup = Guid.Empty; 571 if ((tvClientControl.SelectedNode != null) && (((ClientGroup)tvClientControl.SelectedNode.Tag).Id != Guid.Empty)) { 572 parentgroup = ((ClientGroup)tvClientControl.SelectedNode.Tag).Id; 573 } 574 addgroup.addGroupEvent += new AddGroupDelegate(addgroup_addGroupEvent); 575 addgroup.Show(); 576 } 577 578 private void OnLVClientClicked(object sender, EventArgs e) { 579 currentClient = (ClientInfo)lvClientControl.SelectedItems[0].Tag; 580 ClientClicked(); 581 } 582 583 private void tvClientControl_MouseUp(object sender, MouseEventArgs e) { 584 // If the right mouse button was clicked and released, 585 // display the shortcut menu assigned to the ListView. 586 contextMenuGroup.Items.Clear(); 587 TreeViewHitTestInfo hitTestInfo = tvClientControl.HitTest(e.Location); 588 tvClientControl.SelectedNode = hitTestInfo.Node; 589 if (e.Button != MouseButtons.Right) return; 590 if (hitTestInfo.Node != null) { 591 Resource selectedGroup = (Resource)tvClientControl.SelectedNode.Tag; 592 593 if (selectedGroup != null) { 594 contextMenuGroup.Items.Add(menuItemAddGroup); 595 contextMenuGroup.Items.Add(menuItemDeleteGroup); 596 } 597 } else { 598 contextMenuGroup.Items.Add(menuItemAddGroup); 599 } 600 tvClientControl.ContextMenuStrip.Show(tvClientControl, new Point(e.X, e.Y)); 601 } 602 603 private void addgroup_addGroupEvent(string name) { 604 IClientManager clientManager = ServiceLocator.GetClientManager(); 605 606 if (parentgroup != Guid.Empty) { 607 ClientGroup cg = new ClientGroup() { Name = name }; 608 ResponseObject<ClientGroup> respcg = clientManager.AddClientGroup(cg); 609 Response res = clientManager.AddResourceToGroup(parentgroup, respcg.Obj); 610 if (res != null && !res.Success) { 611 MessageBox.Show(res.StatusMessage, "Error adding Group", MessageBoxButtons.OK, MessageBoxIcon.Error); 612 } 613 } else { 614 ClientGroup cg = new ClientGroup() { Name = name }; 615 clientManager.AddClientGroup(cg); 616 AddClients(); 617 } 618 } 619 620 private void Refresh_Click(object sender, EventArgs e) { 621 Form overlayingForm = new Form(); 622 623 overlayingForm.Show(); 624 overlayingForm.FormBorderStyle = FormBorderStyle.None; 625 overlayingForm.BackColor = Color.Gray; 626 overlayingForm.Opacity = 0.4; 627 overlayingForm.Size = this.Size; 628 overlayingForm.Location = this.Location; 629 630 //Label lbl = new Label(); 631 //overlayingForm.Controls.Add(lbl); 632 //lbl.AutoSize = true; 633 //lbl.Text = "Loading"; 634 //lbl.Name = "lblName"; 635 //lbl.Font = new System.Drawing.Font("Microsoft Sans Serif", 20F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); 636 //lbl.ForeColor = Color.Black; 637 //lbl.BackColor = Color.Transparent; 638 //lbl.Location = new Point(overlayingForm.Width / 2, overlayingForm.Height / 2); 639 640 AddClients(); 641 642 overlayingForm.Close(); 643 } 644 645 private void largeIconsToolStripMenuItem_Click(object sender, EventArgs e) { 646 lvClientControl.View = View.LargeIcon; 647 lvJobControl.View = View.LargeIcon; 648 largeIconsToolStripMenuItem.CheckState = CheckState.Checked; 649 smallIconsToolStripMenuItem.CheckState = CheckState.Unchecked; 650 listToolStripMenuItem.CheckState = CheckState.Unchecked; 651 } 652 653 private void smallIconsToolStripMenuItem_Click(object sender, EventArgs e) { 654 lvClientControl.View = View.SmallIcon; 655 lvJobControl.View = View.SmallIcon; 656 largeIconsToolStripMenuItem.CheckState = CheckState.Unchecked; 657 smallIconsToolStripMenuItem.CheckState = CheckState.Checked; 658 listToolStripMenuItem.CheckState = CheckState.Unchecked; 659 } 660 661 private void listToolStripMenuItem_Click(object sender, EventArgs e) { 662 lvClientControl.View = View.List; 663 lvJobControl.View = View.List; 664 largeIconsToolStripMenuItem.CheckState = CheckState.Unchecked; 665 smallIconsToolStripMenuItem.CheckState = CheckState.Unchecked; 666 listToolStripMenuItem.CheckState = CheckState.Checked; 662 667 } 663 668 #endregion … … 669 674 for (int i = 0; i < oldList.List.Count; i++) { 670 675 newList.Add(i, oldList.List[i]); 671 }672 }673 674 //private void CloneList(ResponseList<ClientInfo> oldList, out IDictionary<int, ClientInfo> newList) {675 // newList = new Dictionary<int, ClientInfo>();676 // for (int i = 0; i < oldList.List.Count; i++) {677 // newList.Add(i, oldList.List[i]);678 // }679 //}680 681 private void CloneList(ResponseList<ClientGroup> oldList, out IDictionary<Guid, ClientGroup> newList) {682 newList = new Dictionary<Guid, ClientGroup>();683 foreach (ClientGroup clientGroup in oldList.List) {684 newList.Add(clientGroup.Id, clientGroup);685 676 } 686 677 } … … 703 694 return 100; 704 695 } 705 706 //private void GetDelta(IList<ClientInfo> oldClient, IDictionary<int, ClientInfo> helpClients) {707 // bool found = false;708 709 // for (int i = 0; i < clientInfo.List.Count; i++) {710 // ClientInfo ci = clientInfo.List[i];711 // for (int j = 0; j < oldClient.Count; j++) {712 // ClientInfo cio = oldClient[j];713 // if (ci.Id.Equals(cio.Id)) {714 // found = true;715 // if ((ci.State != cio.State) || (ci.NrOfFreeCores != cio.NrOfFreeCores)) {716 // changes.Add(new Changes { Types = Type.Client, ID = ci.Id, ChangeType = Change.Update, Position = i });717 // }718 // int removeAt = -1;719 // foreach (KeyValuePair<int, ClientInfo> kvp in helpClients) {720 // if (cio.Id.Equals(kvp.Value.Id)) {721 // removeAt = kvp.Key;722 // break;723 // }724 // }725 // if (removeAt >= 0) {726 // helpClients.Remove(removeAt);727 // }728 // break;729 // }730 // }731 // if (found == false) {732 // changes.Add(new Changes { Types = Type.Client, ID = ci.Id, ChangeType = Change.Create });733 // }734 // found = false;735 // }736 // foreach (KeyValuePair<int, ClientInfo> kvp in helpClients) {737 // changes.Add(new Changes { Types = Type.Client, ID = kvp.Value.Id, ChangeType = Change.Delete, Position = kvp.Key });738 // }739 740 //}741 742 private void DetermineDelta() {743 744 }745 746 //private void GetDelta(IList<ClientGroup> oldClient, IDictionary<Guid, ClientGroup> helpClients) {747 748 // bool found = false;749 // for (int i = 0; i < clients.List.Count; i++) {750 // ClientGroup cg = clientGroups.List[i];751 // for (int j = 0; j < oldClient.Count; i++) {752 // ClientGroup cgo = oldClient[j];753 // if (cg.Id.Equals(cgo.Id)) {754 // found = true;755 // foreach (Resource resource in cg.Resources) {756 // foreach (Resource resourceold in cgo.Resources) {757 // if (resource.Id.Equals(resourceold.Id)) {758 // if (resourceold.Name != resource.Name) {759 // changes.Add(new Changes { Types = Type.Client, ID = cg.Id, ChangeType = Change.Update, Position = i });760 // }761 // }762 // }763 // }764 // for (int k = 0; k < helpClients.Count; k++) {765 // if (cgo.Id.Equals(helpClients[k].Id)) {766 // helpClients.Remove(k);767 // break;768 // }769 // }770 // break;771 // }772 // }773 // if (found == false) {774 // changes.Add(new Changes { Types = Type.ClientGroup, ID = cg.Id, ChangeType = Change.Create });775 // }776 // found = false;777 // }778 // foreach (KeyValuePair<int, ClientGroup> kvp in helpClients) {779 // changes.Add(new Changes { Types = Type.ClientGroup, ID = kvp.Value.Id, ChangeType = Change.Delete, Position = kvp.Key });780 // }781 //}782 696 783 697 private void GetDelta(IList<Job> oldJobs, IDictionary<int, Job> helpJobs) { … … 861 775 #endregion 862 776 863 private void largeIconsToolStripMenuItem_Click(object sender, EventArgs e) { 864 lvClientControl.View = View.LargeIcon; 865 lvJobControl.View = View.LargeIcon; 866 largeIconsToolStripMenuItem.CheckState = CheckState.Checked; 867 smallIconsToolStripMenuItem.CheckState = CheckState.Unchecked; 868 listToolStripMenuItem.CheckState = CheckState.Unchecked; 869 } 870 871 private void smallIconsToolStripMenuItem_Click(object sender, EventArgs e) { 872 lvClientControl.View = View.SmallIcon; 873 lvJobControl.View = View.SmallIcon; 874 largeIconsToolStripMenuItem.CheckState = CheckState.Unchecked; 875 smallIconsToolStripMenuItem.CheckState = CheckState.Checked; 876 listToolStripMenuItem.CheckState = CheckState.Unchecked; 877 } 878 879 private void listToolStripMenuItem_Click(object sender, EventArgs e) { 880 lvClientControl.View = View.List; 881 lvJobControl.View = View.List; 882 largeIconsToolStripMenuItem.CheckState = CheckState.Unchecked; 883 smallIconsToolStripMenuItem.CheckState = CheckState.Unchecked; 884 listToolStripMenuItem.CheckState = CheckState.Checked; 885 } 886 887 private void tvClientControl_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) { 888 lvClientControl.Items.Clear(); 889 lvClientControl.Groups.Clear(); 890 currentNode = e.Node; 891 AddGroupsToListView(e.Node); 892 } 893 894 private void AddGroupsToListView(TreeNode node) { 895 if (node != null) { 896 ListViewGroup lvg = new ListViewGroup(node.Text, HorizontalAlignment.Left); 897 lvClientControl.Groups.Add(lvg); 898 foreach (ListViewItem item in clientList[((ClientGroup)node.Tag).Id]) { 899 item.Group = lvg; 900 lvClientControl.Items.Add(item); 901 } 902 903 if (node.Nodes != null) { 904 foreach (TreeNode curNode in node.Nodes) { 905 AddGroupsToListView(curNode); 906 } 907 } 908 } 909 } 910 911 private void Refresh_Click(object sender, EventArgs e) { 912 Form overlayingForm = new Form(); 913 914 overlayingForm.Show(); 915 overlayingForm.FormBorderStyle = FormBorderStyle.None; 916 overlayingForm.BackColor = Color.Gray; 917 overlayingForm.Opacity = 0.4; 918 overlayingForm.Size = this.Size; 919 overlayingForm.Location = this.Location; 920 921 //Label lbl = new Label(); 922 //overlayingForm.Controls.Add(lbl); 923 //lbl.AutoSize = true; 924 //lbl.Text = "Loading"; 925 //lbl.Name = "lblName"; 926 //lbl.Font = new System.Drawing.Font("Microsoft Sans Serif", 20F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); 927 //lbl.ForeColor = Color.Black; 928 //lbl.BackColor = Color.Transparent; 929 //lbl.Location = new Point(overlayingForm.Width / 2, overlayingForm.Height / 2); 930 931 AddClients(); 932 933 overlayingForm.Close(); 934 } 935 936 private void tvClientControl_MouseUp(object sender, MouseEventArgs e) { 937 // If the right mouse button was clicked and released, 938 // display the shortcut menu assigned to the ListView. 939 contextMenuGroup.Items.Clear(); 940 TreeViewHitTestInfo hitTestInfo = tvClientControl.HitTest(e.Location); 941 tvClientControl.SelectedNode = hitTestInfo.Node; 942 if (e.Button != MouseButtons.Right) return; 943 if (hitTestInfo.Node != null) { 944 Resource selectedGroup = (Resource)tvClientControl.SelectedNode.Tag; 945 946 if (selectedGroup != null) { 947 contextMenuGroup.Items.Add(menuItemAddGroup); 948 contextMenuGroup.Items.Add(menuItemDeleteGroup); 949 } 950 } else { 951 contextMenuGroup.Items.Add(menuItemAddGroup); 952 } 953 tvClientControl.ContextMenuStrip.Show(new Point(e.X, e.Y)); 954 } 777 955 778 } 956 779 }
Note: See TracChangeset
for help on using the changeset viewer.