Free cookie consent management tool by TermsFeed Policy Generator

Changeset 6756


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

#1233 adapted Administrator UI to be more like OKB

Location:
branches/HeuristicLab.Hive-3.4/sources
Files:
1 added
14 edited
2 copied

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Administrator/3.3/HeuristicLab.Clients.Hive.Administrator-3.3.csproj

    r6701 r6756  
    153153  </ItemGroup>
    154154  <ItemGroup>
    155     <Compile Include="HiveAdministratorClient.cs" />
    156155    <Compile Include="Views\HiveAdministratorView.cs">
    157156      <SubType>UserControl</SubType>
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Administrator/3.3/Views/Common/UpdateControl.cs

    r6743 r6756  
    2121
    2222using System;
     23using System.Threading.Tasks;
    2324using System.Windows.Forms;
    2425using TS = System.Threading.Tasks;
     
    5859
    5960        Action action = new Action(PrivUpdateAction);
    60         TS.Task task = new TS.Task(action);
    61         task.Start();
     61        TS.Task.Factory.StartNew(action).ContinueWith((t) => {
     62          throw t.Exception;
     63        }, TaskContinuationOptions.OnlyOnFaulted);
    6264      }
    6365    }
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Administrator/3.3/Views/HiveAdministratorView.cs

    r6734 r6756  
    2121
    2222using System.Windows.Forms;
    23 using HeuristicLab.Core.Views;
    2423using HeuristicLab.MainForm;
     24using HeuristicLab.MainForm.WindowsForms;
    2525
    2626namespace HeuristicLab.Clients.Hive.Administrator.Views {
    2727  [View("Hive Administrator")]
    28   [Content(typeof(HiveAdministratorClient), IsDefaultView = true)]
    29   public partial class HiveAdministratorView : ItemView {
    30     public new HiveAdministratorClient Content {
    31       get { return (HiveAdministratorClient)base.Content; }
     28  [Content(typeof(HiveAdminClient), IsDefaultView = true)]
     29  public partial class HiveAdministratorView : AsynchronousContentView {
     30    public new HiveAdminClient Content {
     31      get { return (HiveAdminClient)base.Content; }
    3232      set { base.Content = value; }
    3333    }
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Administrator/3.3/Views/MenuItems/AdministratorMenuItem.cs

    r6688 r6756  
    2121
    2222using System.Collections.Generic;
    23 using HeuristicLab.Clients.Hive.Administrator;
     23using HeuristicLab.Clients.Hive;
    2424using HeuristicLab.MainForm;
    2525
     
    3333    }
    3434    public override void Execute() {
    35       MainFormManager.MainForm.ShowContent(new HiveAdministratorClient());
     35      MainFormManager.MainForm.ShowContent(HiveAdminClient.Instance);
    3636    }
    3737    public override int Position {
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Administrator/3.3/Views/ResourcesView.Designer.cs

    r6688 r6756  
    6161      this.updateScheduleControl = new HeuristicLab.Clients.Hive.Administrator.Views.Common.UpdateControl();
    6262      this.scheduleView = new HeuristicLab.Clients.Hive.Administrator.Views.ScheduleView();
     63      this.progressBar = new System.Windows.Forms.ProgressBar();
    6364      ((System.ComponentModel.ISupportInitialize)(this.splitSlaves)).BeginInit();
    6465      this.splitSlaves.Panel1.SuspendLayout();
     
    8687      // splitSlaves.Panel1
    8788      //
     89      this.splitSlaves.Panel1.Controls.Add(this.progressBar);
    8890      this.splitSlaves.Panel1.Controls.Add(this.updateSlaveGroup);
    8991      this.splitSlaves.Panel1.Controls.Add(this.btnSave);
     
    224226      this.scheduleView.Name = "scheduleView";
    225227      this.scheduleView.ReadOnly = false;
    226       this.scheduleView.ResourceId = new System.Guid("00000000-0000-0000-0000-000000000000");
    227228      this.scheduleView.Size = new System.Drawing.Size(568, 473);
    228229      this.scheduleView.TabIndex = 0;
     230      //
     231      // progressBar
     232      //
     233      this.progressBar.Location = new System.Drawing.Point(176, 3);
     234      this.progressBar.Name = "progressBar";
     235      this.progressBar.Size = new System.Drawing.Size(70, 23);
     236      this.progressBar.Style = System.Windows.Forms.ProgressBarStyle.Continuous;
     237      this.progressBar.TabIndex = 7;
    229238      //
    230239      // ResourcesView
     
    261270    private System.Windows.Forms.Button btnSave;
    262271    private UpdateControl updateSlaveGroup;
     272    private System.Windows.Forms.ProgressBar progressBar;
    263273  }
    264274}
  • 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    }
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Administrator/3.3/Views/ScheduleView.cs

    r6696 r6756  
    3232
    3333namespace HeuristicLab.Clients.Hive.Administrator.Views {
    34   [View("ScheduleView")]
     34  [View("Schedule View")]
    3535  [Content(typeof(IItemList<Downtime>), IsDefaultView = true)]
    3636  public partial class ScheduleView : ItemView {
     
    4747    public delegate void OnDialogClosedDelegate(RecurrentEvent e);
    4848
    49     private Guid resourceId;
    50     public Guid ResourceId {
    51       get {
    52         return resourceId;
    53       }
    54       set {
    55         resourceId = value;
    56       }
    57     }
    58 
    5949    public ScheduleView() {
    6050      InitializeComponent();
     
    9383    private void UpdateCalendarFromContent() {
    9484      offlineTimes.Clear();
    95       foreach (Downtime app in Content) {
    96         offlineTimes.Add(new HiveAppointment {
    97           AllDayEvent = app.AllDayEvent,
    98           EndDate = app.EndDate,
    99           StartDate = app.StartDate,
    100           Recurring = app.Recurring,
    101           RecurringId = app.RecurringId,
    102           BorderColor = Color.Red,
    103           Locked = true,
    104           Subject = "Offline",
    105           Changed = false,
    106           Id = app.Id
    107         });
     85      if (Content != null) {
     86        foreach (Downtime app in Content) {
     87          offlineTimes.Add(ToHiveAppointment(app));
     88        }
    10889      }
    10990      dvOnline.Invalidate();
     
    233214    #region Register Content Events
    234215    protected override void DeregisterContentEvents() {
    235       // TODO: Deregister your event handlers on the Content here
    236216      base.DeregisterContentEvents();
    237217    }
    238218    protected override void RegisterContentEvents() {
    239219      base.RegisterContentEvents();
    240       // TODO: Register your event handlers on the Content here
    241220    }
    242221    #endregion
     
    244223    protected override void OnContentChanged() {
    245224      base.OnContentChanged();
    246       if (Content == null) {
    247         // TODO: Put code here when content is null
    248       } else {
    249         UpdateCalendarFromContent();
    250       }
     225      UpdateCalendarFromContent();
    251226    }
    252227
    253228    protected override void SetEnabledStateOfControls() {
    254229      base.SetEnabledStateOfControls();
    255       // TODO: Put code here to enable or disable controls based on whether the Content is/not null or the view is ReadOnly
    256230    }
    257231
     
    333307      List<Downtime> appointments = new List<Downtime>();
    334308      foreach (HiveAppointment app in offlineTimes) {
    335         if (app.Deleted) {
    336           ServiceLocator.Instance.CallHiveService(service => {
    337             if (app.Id != Guid.Empty) {
    338               service.DeleteDowntime(app.Id);
    339             }
    340           });
    341         } else if (app.Changed) {
    342           Downtime apdto = new Downtime {
    343             AllDayEvent = app.AllDayEvent,
    344             EndDate = app.EndDate,
    345             Recurring = app.Recurring,
    346             RecurringId = app.RecurringId,
    347             StartDate = app.StartDate,
    348             ResourceId = resourceId
    349           };
    350           appointments.Add(apdto);
    351         }
    352       }
    353 
    354       if (appointments.Count > 0) {
    355         //TODO: find a sane way to do this
    356         ServiceLocator.Instance.CallHiveService(service => {
    357           foreach (Downtime app in appointments) {
    358             service.AddDowntime(app);
    359           }
    360         });
    361       }
     309        if (app.Deleted && app.Id != Guid.Empty) {
     310          HiveAdminClient.Delete(ToDowntime(app));
     311        } else if (app.Changed || app.Id == null || app.Id == Guid.Empty) {
     312          Downtime dt = ToDowntime(app);
     313          appointments.Add(dt);
     314        }
     315      }
     316      foreach (Downtime dt in appointments) {
     317        dt.Store();
     318      }
     319    }
     320
     321    private HiveAppointment ToHiveAppointment(Downtime downtime) {
     322      HiveAppointment app = new HiveAppointment {
     323        AllDayEvent = downtime.AllDayEvent,
     324        EndDate = downtime.EndDate,
     325        StartDate = downtime.StartDate,
     326        Recurring = downtime.Recurring,
     327        RecurringId = downtime.RecurringId,
     328        Deleted = false,
     329        BorderColor = Color.Red,
     330        Locked = true,
     331        Subject = "Offline",
     332        Changed = downtime.Modified,
     333        Id = downtime.Id
     334      };
     335      return app;
     336    }
     337
     338    private Downtime ToDowntime(HiveAppointment app) {
     339      Downtime downtime = new Downtime {
     340        AllDayEvent = app.AllDayEvent,
     341        EndDate = app.EndDate,
     342        StartDate = app.StartDate,
     343        Recurring = app.Recurring,
     344        RecurringId = app.RecurringId,
     345        ResourceId = HiveAdminClient.Instance.DowntimeForResourceId,
     346        Id = app.Id
     347      };
     348      return downtime;
    362349    }
    363350  }
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.3/HeuristicLab.Clients.Hive-3.3.csproj

    r6744 r6756  
    112112  </ItemGroup>
    113113  <ItemGroup>
     114    <Compile Include="HiveAdminClient.cs" />
    114115    <Compile Include="HiveClient.cs" />
    115116    <Compile Include="Settings.Designer.cs">
     
    120121    <Compile Include="Tasks\ItemTask.cs" />
    121122    <Compile Include="RefreshableJob.cs" />
    122     <Compile Include="ServiceClients\HiveExperimentPermission.cs" />
     123    <Compile Include="ServiceClients\JobPermission.cs" />
    123124    <Compile Include="StateLogList.cs" />
    124125    <Compile Include="StateLogListList.cs" />
     
    167168    <Compile Include="ServiceClients\Resource.cs" />
    168169    <Compile Include="ServiceClients\StateLog.cs" />
    169     <Compile Include="ServiceClients\HiveExperiment.cs" />
     170    <Compile Include="ServiceClients\Job.cs" />
    170171    <Compile Include="ServiceClients\SlaveGroup.cs" />
    171172    <Compile Include="ServiceClients\Slave.cs" />
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.3/HiveClient.cs

    r6744 r6756  
    7575    #endregion
    7676
    77     public HiveClient() { }
     77    private HiveClient() { }
    7878
    7979    #region Refresh
     
    101101        }
    102102        // remove those which were not in the list of loaded hiveexperiments
    103         foreach (var experiment in oldJobs) {
    104           if (experiment.Id == Guid.Empty) {
     103        foreach (var job in oldJobs) {
     104          if (job.Id == Guid.Empty) {
    105105            // experiment not uploaded... keep
    106             jobs.Add(experiment);
     106            jobs.Add(job);
    107107          } else {
    108             experiment.RefreshAutomatically = false; // stop results polling
     108            job.RefreshAutomatically = false; // stop results polling
    109109          }
    110110        }
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.3/ServiceClients/Downtime.cs

    r6452 r6756  
    2727    public Downtime() { }
    2828
     29    public override void Store() {
     30      HiveAdminClient.Store(this, new System.Threading.CancellationToken());
     31      Modified = false;
     32    }
     33
    2934    protected Downtime(Downtime original, Cloner cloner)
    3035      : base(original, cloner) {
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.3/ServiceClients/HiveItem.cs

    r6479 r6756  
    8585    #endregion
    8686
    87     public void Store() {
     87    public virtual void Store() {
    8888      HiveClient.Store(this, new System.Threading.CancellationToken());
    8989      Modified = false;
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive/3.3/ServiceClients/Resource.cs

    r6372 r6756  
    2828    public Resource() { }
    2929
     30    public override void Store() {
     31      HiveAdminClient.Store(this, new System.Threading.CancellationToken());
     32      Modified = false;
     33    }
     34
    3035    protected Resource(Resource original, Cloner cloner)
    3136      : base(original, cloner) {
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.3/Enums/Permission.cs

    r6717 r6756  
    3131
    3232    /// <summary>
    33     /// User can only download and view experiments
     33    /// User can only download and view jobs
    3434    /// </summary>
    3535    Read,
    3636
    3737    /// <summary>
    38     /// User can pause, stop, restart, delete experiment. can also grant other
     38    /// User can pause, stop, restart, delete jobs. can also grant other
    3939    /// </summary>
    4040    Full
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive/3.3/HiveDao.cs

    r6743 r6756  
    233233    public DT.Job GetJob(Guid id) {
    234234      using (var db = CreateContext()) {
    235         return AddStatsToExperiment(db, DT.Convert.ToDto(db.Jobs.SingleOrDefault(x => x.JobId == id)));
    236       }
    237     }
    238 
    239     private DT.Job AddStatsToExperiment(HiveDataContext db, DT.Job exp) {
     235        return AddStatsToJob(db, DT.Convert.ToDto(db.Jobs.SingleOrDefault(x => x.JobId == id)));
     236      }
     237    }
     238
     239    private DT.Job AddStatsToJob(HiveDataContext db, DT.Job exp) {
    240240      if (exp == null)
    241241        return null;
     
    250250    public IEnumerable<DT.Job> GetJobs(Expression<Func<Job, bool>> predicate) {
    251251      using (var db = CreateContext()) {
    252         return db.Jobs.Where(predicate).Select(x => AddStatsToExperiment(db, DT.Convert.ToDto(x))).ToArray();
     252        return db.Jobs.Where(predicate).Select(x => AddStatsToJob(db, DT.Convert.ToDto(x))).ToArray();
    253253      }
    254254    }
Note: See TracChangeset for help on using the changeset viewer.