Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/13/11 19:29:56 (13 years ago)
Author:
ascheibe
Message:

#1233 adapted Administrator UI to be more like OKB

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Administrator/3.3/Views/ResourcesView.cs

    r6734 r6756  
    2323using System.Drawing;
    2424using System.Linq;
     25using System.Threading;
     26using System.Threading.Tasks;
    2527using System.Windows.Forms;
    2628using HeuristicLab.Clients.Hive.Views;
     
    2830using HeuristicLab.Core.Views;
    2931using HeuristicLab.MainForm;
     32using TS = System.Threading.Tasks;
    3033
    3134namespace HeuristicLab.Clients.Hive.Administrator.Views {
    32   [View("ResourcesView")]
     35  [View("Resources View")]
    3336  [Content(typeof(IItemList<Resource>), IsDefaultView = true)]
    34   public partial class ResourcesView : ItemView {
     37  public partial class ResourcesView : ItemView, IDisposable {
    3538    public new IItemList<Resource> Content {
    3639      get { return (IItemList<Resource>)base.Content; }
     
    4144    private const int slaveImageIndex = 0;
    4245    private const int slaveGroupImageIndex = 1;
     46    private TS.Task progressTask;
     47    private bool stopProgressTask;
    4348
    4449
     
    4752      treeSlaveGroup.ImageList.Images.Add(HiveImageLibrary.Slave);
    4853      treeSlaveGroup.ImageList.Images.Add(HiveImageLibrary.SlaveGroup);
     54      //TODO: remove updatecontrol and replace with a regular button
    4955      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;
    5387    }
    5488
     
    142176
    143177      slaveView.Content = (Resource)e.Node.Tag;
    144       scheduleView.ResourceId = ((Resource)e.Node.Tag).Id;
     178      HiveAdminClient.Instance.DowntimeForResourceId = ((Resource)e.Node.Tag).Id;
    145179
    146180      if (e.Node.Tag is SlaveGroup) {
     
    149183
    150184      if (tabSlaveGroup.SelectedIndex == 1) {
    151         UpdateSchedule();
     185        UpdateScheduleAsync();
    152186      }
    153187    }
     
    175209        Resource res = (Resource)treeSlaveGroup.SelectedNode.Tag;
    176210
    177         DialogResult diagRes = MessageBox.Show("Do you really want to delete " + res.Name + "?", "HeuristicLab Hive Administration", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
     211        DialogResult diagRes = MessageBox.Show("Do you really want to delete " + res.Name + "?", "HeuristicLab Hive Administrator", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
    178212        if (diagRes == DialogResult.Yes) {
    179213          if (res is Slave) {
    180214            Content.Remove(res);
    181             ServiceLocator.Instance.CallHiveService(service => service.DeleteSlave(res.Id));
     215            HiveAdminClient.Delete(res);
    182216          } else if (res is SlaveGroup) {
    183217            //only delete empty groups
    184218            if (Content.Where(s => s.ParentResourceId == res.Id).Count() < 1) {
    185219              Content.Remove(res);
    186               ServiceLocator.Instance.CallHiveService(service => service.DeleteSlaveGroup(res.Id));
     220              HiveAdminClient.Delete(res);
    187221            } else {
    188               MessageBox.Show("Only empty groups can be deleted.", "HeuristicLab Hive Administration", MessageBoxButtons.OK, MessageBoxIcon.Error);
     222              MessageBox.Show("Only empty groups can be deleted.", "HeuristicLab Hive Administrator", MessageBoxButtons.OK, MessageBoxIcon.Error);
    189223            }
    190224          }
     
    197231        if (res is SlaveGroup && res.Id == Guid.Empty) {
    198232          SlaveGroup slaveGroup = (SlaveGroup)res;
    199           ServiceLocator.Instance.CallHiveService(service => slaveGroup.Id = service.AddSlaveGroup(slaveGroup));
     233          slaveGroup.Store();
    200234        }
    201235        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();
    207237        }
    208238      }
     
    218248          if (destNode.Text == ungroupedGroupName || (destNode.Parent != null && destNode.Parent.Text == ungroupedGroupName)) {
    219249            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 Administration", MessageBoxButtons.OK, MessageBoxIcon.Information);
     250              ungroupedGroupName, Environment.NewLine), "HeuristicLab Hive Administrator", MessageBoxButtons.OK, MessageBoxIcon.Information);
    221251            return;
    222252          }
     
    239269            //save parent group to get an id
    240270            if (sgrp.Id == Guid.Empty) {
    241               ServiceLocator.Instance.CallHiveService(service => sgrp.Id = service.AddSlaveGroup(sgrp));
     271              sgrp.Store();
    242272            }
    243273
     
    300330      }
    301331      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() {
    306339      if (this.InvokeRequired) {
    307340        this.Invoke(new Action(ResetView));
     
    310343      }
    311344
    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);
    319353    }
    320354
    321355    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");
    331368    }
    332369
    333370    private void tabSlaveGroup_SelectedIndexChanged(object sender, EventArgs e) {
    334371      if (tabSlaveGroup.SelectedIndex == 1) {
    335         UpdateSchedule();
     372        UpdateScheduleAsync();
    336373      }
    337374    }
Note: See TracChangeset for help on using the changeset viewer.