Changeset 6756 for branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Administrator/3.3/Views/ResourcesView.cs
- Timestamp:
- 09/13/11 19:29:56 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Administrator/3.3/Views/ResourcesView.cs
r6734 r6756 23 23 using System.Drawing; 24 24 using System.Linq; 25 using System.Threading; 26 using System.Threading.Tasks; 25 27 using System.Windows.Forms; 26 28 using HeuristicLab.Clients.Hive.Views; … … 28 30 using HeuristicLab.Core.Views; 29 31 using HeuristicLab.MainForm; 32 using TS = System.Threading.Tasks; 30 33 31 34 namespace HeuristicLab.Clients.Hive.Administrator.Views { 32 [View("Resources View")]35 [View("Resources View")] 33 36 [Content(typeof(IItemList<Resource>), IsDefaultView = true)] 34 public partial class ResourcesView : ItemView {37 public partial class ResourcesView : ItemView, IDisposable { 35 38 public new IItemList<Resource> Content { 36 39 get { return (IItemList<Resource>)base.Content; } … … 41 44 private const int slaveImageIndex = 0; 42 45 private const int slaveGroupImageIndex = 1; 46 private TS.Task progressTask; 47 private bool stopProgressTask; 43 48 44 49 … … 47 52 treeSlaveGroup.ImageList.Images.Add(HiveImageLibrary.Slave); 48 53 treeSlaveGroup.ImageList.Images.Add(HiveImageLibrary.SlaveGroup); 54 //TODO: remove updatecontrol and replace with a regular button 49 55 updateScheduleControl.UpdateAction = new Action(UpdateSchedule); 50 updateSlaveGroup.UpdateAction = new Action(UpdateSlaveGroups); 51 52 updateSlaveGroup.Update(); 56 updateSlaveGroup.UpdateAction = new Action(UpdateResources); 57 58 HiveAdminClient.Instance.Refreshing += new EventHandler(Instance_Refreshing); 59 HiveAdminClient.Instance.Refreshed += new EventHandler(Instance_Refreshed); 60 61 UpdateResourcesAsync(); 62 } 63 64 public new void Dispose() { 65 HiveAdminClient.Instance.Refreshing -= new EventHandler(Instance_Refreshing); 66 HiveAdminClient.Instance.Refreshed -= new EventHandler(Instance_Refreshed); 67 } 68 69 private void UpdateProgress() { 70 while (!stopProgressTask) { 71 int diff = (progressBar.Maximum - progressBar.Minimum) / 10; 72 progressBar.Value = (progressBar.Value + diff) % progressBar.Maximum; 73 //ok, this is not very clever... 74 Thread.Sleep(500); 75 } 76 progressBar.Value = progressBar.Minimum; 77 } 78 79 void Instance_Refreshing(object sender, EventArgs e) { 80 stopProgressTask = false; 81 progressTask = new TS.Task(UpdateProgress); 82 progressTask.Start(); 83 } 84 85 void Instance_Refreshed(object sender, EventArgs e) { 86 stopProgressTask = true; 53 87 } 54 88 … … 142 176 143 177 slaveView.Content = (Resource)e.Node.Tag; 144 scheduleView.ResourceId = ((Resource)e.Node.Tag).Id;178 HiveAdminClient.Instance.DowntimeForResourceId = ((Resource)e.Node.Tag).Id; 145 179 146 180 if (e.Node.Tag is SlaveGroup) { … … 149 183 150 184 if (tabSlaveGroup.SelectedIndex == 1) { 151 UpdateSchedule ();185 UpdateScheduleAsync(); 152 186 } 153 187 } … … 175 209 Resource res = (Resource)treeSlaveGroup.SelectedNode.Tag; 176 210 177 DialogResult diagRes = MessageBox.Show("Do you really want to delete " + res.Name + "?", "HeuristicLab Hive Administrat ion", MessageBoxButtons.YesNo, MessageBoxIcon.Question);211 DialogResult diagRes = MessageBox.Show("Do you really want to delete " + res.Name + "?", "HeuristicLab Hive Administrator", MessageBoxButtons.YesNo, MessageBoxIcon.Question); 178 212 if (diagRes == DialogResult.Yes) { 179 213 if (res is Slave) { 180 214 Content.Remove(res); 181 ServiceLocator.Instance.CallHiveService(service => service.DeleteSlave(res.Id));215 HiveAdminClient.Delete(res); 182 216 } else if (res is SlaveGroup) { 183 217 //only delete empty groups 184 218 if (Content.Where(s => s.ParentResourceId == res.Id).Count() < 1) { 185 219 Content.Remove(res); 186 ServiceLocator.Instance.CallHiveService(service => service.DeleteSlaveGroup(res.Id));220 HiveAdminClient.Delete(res); 187 221 } else { 188 MessageBox.Show("Only empty groups can be deleted.", "HeuristicLab Hive Administrat ion", MessageBoxButtons.OK, MessageBoxIcon.Error);222 MessageBox.Show("Only empty groups can be deleted.", "HeuristicLab Hive Administrator", MessageBoxButtons.OK, MessageBoxIcon.Error); 189 223 } 190 224 } … … 197 231 if (res is SlaveGroup && res.Id == Guid.Empty) { 198 232 SlaveGroup slaveGroup = (SlaveGroup)res; 199 ServiceLocator.Instance.CallHiveService(service => slaveGroup.Id = service.AddSlaveGroup(slaveGroup));233 slaveGroup.Store(); 200 234 } 201 235 if (res.Id != Guid.Empty && res.Modified) { 202 if (res is SlaveGroup) { 203 ServiceLocator.Instance.CallHiveService(service => service.UpdateSlaveGroup((SlaveGroup)res)); 204 } else if (res is Slave) { 205 ServiceLocator.Instance.CallHiveService(service => service.UpdateSlave((Slave)res)); 206 } 236 res.Store(); 207 237 } 208 238 } … … 218 248 if (destNode.Text == ungroupedGroupName || (destNode.Parent != null && destNode.Parent.Text == ungroupedGroupName)) { 219 249 MessageBox.Show(String.Format("You can't drag items to the {0} group.{1}This group only contains slaves which haven't yet been assigned to a real group.", 220 ungroupedGroupName, Environment.NewLine), "HeuristicLab Hive Administrat ion", MessageBoxButtons.OK, MessageBoxIcon.Information);250 ungroupedGroupName, Environment.NewLine), "HeuristicLab Hive Administrator", MessageBoxButtons.OK, MessageBoxIcon.Information); 221 251 return; 222 252 } … … 239 269 //save parent group to get an id 240 270 if (sgrp.Id == Guid.Empty) { 241 ServiceLocator.Instance.CallHiveService(service => sgrp.Id = service.AddSlaveGroup(sgrp));271 sgrp.Store(); 242 272 } 243 273 … … 300 330 } 301 331 slaveView.Content = null; 302 scheduleView.ResourceId = Guid.Empty; 303 } 304 305 private void UpdateSlaveGroups() { 332 if (scheduleView.Content != null) { 333 scheduleView.Content.Clear(); 334 } 335 HiveAdminClient.Instance.ResetDowntime(); 336 } 337 338 private void UpdateResources() { 306 339 if (this.InvokeRequired) { 307 340 this.Invoke(new Action(ResetView)); … … 310 343 } 311 344 312 IItemList<Resource> resources = new ItemList<Resource>(); 313 314 ServiceLocator.Instance.CallHiveService(service => { 315 service.GetSlaveGroups().ForEach(g => resources.Add(g)); 316 service.GetSlaves().ForEach(s => resources.Add(s)); 317 }); 318 Content = resources; 345 HiveAdminClient.Instance.Refresh(); 346 Content = HiveAdminClient.Instance.Resources; 347 } 348 349 private void UpdateResourcesAsync() { 350 TS.Task.Factory.StartNew(UpdateResources).ContinueWith((t) => { 351 DisplayError(t.Exception); 352 }, TaskContinuationOptions.OnlyOnFaulted); 319 353 } 320 354 321 355 private void UpdateSchedule() { 322 Guid resourceId = scheduleView.ResourceId; 323 if (resourceId != null) { 324 ServiceLocator.Instance.CallHiveService(service => { 325 var appointments = service.GetDowntimesForResource(resourceId); 326 ItemList<Downtime> ias = new ItemList<Downtime>(); 327 appointments.ForEach(a => ias.Add(a)); 328 scheduleView.Invoke(new Action(() => scheduleView.Content = ias)); 329 }); 330 } 356 HiveAdminClient.Instance.RefreshCalendar(); 357 scheduleView.Invoke(new Action(() => scheduleView.Content = HiveAdminClient.Instance.Downtimes)); 358 } 359 360 private void UpdateScheduleAsync() { 361 TS.Task.Factory.StartNew(UpdateSchedule).ContinueWith((t) => { 362 DisplayError(t.Exception); 363 }, TaskContinuationOptions.OnlyOnFaulted); 364 } 365 366 private void DisplayError(Exception ex) { 367 MessageBox.Show("An error occured updating the schedule: " + Environment.NewLine + ex.ToString(), "HeuristicLab Hive Administrator"); 331 368 } 332 369 333 370 private void tabSlaveGroup_SelectedIndexChanged(object sender, EventArgs e) { 334 371 if (tabSlaveGroup.SelectedIndex == 1) { 335 UpdateSchedule ();372 UpdateScheduleAsync(); 336 373 } 337 374 }
Note: See TracChangeset
for help on using the changeset viewer.