Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/04/17 13:56:38 (7 years ago)
Author:
jkarder
Message:

#2839:

  • worked on hive administrator view
  • updated service clients
Location:
branches/HiveProjectManagement/HeuristicLab.Clients.Hive.Administrator/3.3/Views
Files:
4 added
3 edited

Legend:

Unmodified
Added
Removed
  • branches/HiveProjectManagement/HeuristicLab.Clients.Hive.Administrator/3.3/Views/HiveAdministratorView.Designer.cs

    r14185 r15401  
    3030      this.tabAdmin = new System.Windows.Forms.TabControl();
    3131      this.tabSlaves = new System.Windows.Forms.TabPage();
     32      this.resourcesView = new HeuristicLab.Clients.Hive.Administrator.Views.ResourcesView();
     33      this.tabPage1 = new System.Windows.Forms.TabPage();
    3234      this.imageListUsers = new System.Windows.Forms.ImageList(this.components);
    33       this.resourcesView = new HeuristicLab.Clients.Hive.Administrator.Views.ResourcesView();
     35      this.projectsView = new HeuristicLab.Clients.Hive.Administrator.Views.ProjectsView();
    3436      this.tabAdmin.SuspendLayout();
    3537      this.tabSlaves.SuspendLayout();
     38      this.tabPage1.SuspendLayout();
    3639      this.SuspendLayout();
    3740      //
    3841      // tabAdmin
    3942      //
    40       this.tabAdmin.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    41                   | System.Windows.Forms.AnchorStyles.Left)
    42                   | System.Windows.Forms.AnchorStyles.Right)));
     43      this.tabAdmin.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
     44            | System.Windows.Forms.AnchorStyles.Left)
     45            | System.Windows.Forms.AnchorStyles.Right)));
    4346      this.tabAdmin.Controls.Add(this.tabSlaves);
     47      this.tabAdmin.Controls.Add(this.tabPage1);
    4448      this.tabAdmin.Location = new System.Drawing.Point(3, 0);
    4549      this.tabAdmin.Name = "tabAdmin";
     
    5963      this.tabSlaves.UseVisualStyleBackColor = true;
    6064      //
    61       // imageListUsers
    62       //
    63       this.imageListUsers.ColorDepth = System.Windows.Forms.ColorDepth.Depth32Bit;
    64       this.imageListUsers.ImageSize = new System.Drawing.Size(16, 16);
    65       this.imageListUsers.TransparentColor = System.Drawing.Color.Transparent;
    66       //
    6765      // resourcesView
    6866      //
    69       this.resourcesView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    70                   | System.Windows.Forms.AnchorStyles.Left)
    71                   | System.Windows.Forms.AnchorStyles.Right)));
     67      this.resourcesView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
     68            | System.Windows.Forms.AnchorStyles.Left)
     69            | System.Windows.Forms.AnchorStyles.Right)));
    7270      this.resourcesView.Caption = "ResourcesView";
    7371      this.resourcesView.Content = null;
     
    7876      this.resourcesView.TabIndex = 0;
    7977      //
    80       // HiveAdministrationView
     78      // tabPage1
    8179      //
    82       this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
     80      this.tabPage1.Controls.Add(this.projectsView);
     81      this.tabPage1.Location = new System.Drawing.Point(4, 22);
     82      this.tabPage1.Name = "tabPage1";
     83      this.tabPage1.Size = new System.Drawing.Size(734, 520);
     84      this.tabPage1.TabIndex = 4;
     85      this.tabPage1.Text = "Projects";
     86      this.tabPage1.UseVisualStyleBackColor = true;
     87      //
     88      // imageListUsers
     89      //
     90      this.imageListUsers.ColorDepth = System.Windows.Forms.ColorDepth.Depth32Bit;
     91      this.imageListUsers.ImageSize = new System.Drawing.Size(16, 16);
     92      this.imageListUsers.TransparentColor = System.Drawing.Color.Transparent;
     93      //
     94      // projectsView
     95      //
     96      this.projectsView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     97            | System.Windows.Forms.AnchorStyles.Left)
     98            | System.Windows.Forms.AnchorStyles.Right)));
     99      this.projectsView.Caption = "Resources View";
     100      this.projectsView.Content = null;
     101      this.projectsView.Location = new System.Drawing.Point(0, 0);
     102      this.projectsView.Name = "projectsView";
     103      this.projectsView.ReadOnly = false;
     104      this.projectsView.Size = new System.Drawing.Size(734, 520);
     105      this.projectsView.TabIndex = 0;
     106      //
     107      // HiveAdministratorView
     108      //
    83109      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit;
    84110      this.Controls.Add(this.tabAdmin);
    85       this.Name = "HiveAdministrationView";
     111      this.Name = "HiveAdministratorView";
    86112      this.Size = new System.Drawing.Size(745, 546);
    87113      this.tabAdmin.ResumeLayout(false);
    88114      this.tabSlaves.ResumeLayout(false);
     115      this.tabPage1.ResumeLayout(false);
    89116      this.ResumeLayout(false);
    90117
     
    96123    private System.Windows.Forms.ImageList imageListUsers;
    97124    private System.Windows.Forms.TabPage tabSlaves;
    98 
     125    private System.Windows.Forms.TabPage tabPage1;
     126    private ProjectsView projectsView;
    99127  }
    100128}
  • branches/HiveProjectManagement/HeuristicLab.Clients.Hive.Administrator/3.3/Views/ResourcesView.Designer.cs

    r14185 r15401  
    3737        components.Dispose();
    3838      }
    39       HiveAdminClient.Instance.Refreshing -= new EventHandler(Instance_Refreshing);
    40       HiveAdminClient.Instance.Refreshed -= new EventHandler(Instance_Refreshed);
    41 
    42       Access.AccessClient.Instance.Refreshing -= new EventHandler(AccessClient_Refreshing);
    43       Access.AccessClient.Instance.Refreshed -= new EventHandler(AccessClient_Refreshed);
     39      HiveAdminClient.Instance.Refreshing -= new EventHandler(HiveAdminClient_Instance_Refreshing);
     40      HiveAdminClient.Instance.Refreshed -= new EventHandler(HiveAdminClient_Instance_Refreshed);
     41
     42      Access.AccessClient.Instance.Refreshing -= new EventHandler(AccessClient_Instance_Refreshing);
     43      Access.AccessClient.Instance.Refreshed -= new EventHandler(AccessClient_Instance_Refreshed);
    4444      base.Dispose(disposing);
    4545    }
     
    5353    private void InitializeComponent() {
    5454      this.components = new System.ComponentModel.Container();
     55      System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ResourcesView));
    5556      this.imageListSlaveGroups = new System.Windows.Forms.ImageList(this.components);
    5657      this.splitSlaves = new System.Windows.Forms.SplitContainer();
    5758      this.btnRefresh = new System.Windows.Forms.Button();
    58       this.progressBar = new System.Windows.Forms.ProgressBar();
    5959      this.btnSave = new System.Windows.Forms.Button();
    6060      this.btnRemoveGroup = new System.Windows.Forms.Button();
    6161      this.btnAddGroup = new System.Windows.Forms.Button();
    62       this.btnPermissionsSave = new System.Windows.Forms.Button();
    6362      this.treeSlaveGroup = new System.Windows.Forms.TreeView();
    6463      this.tabSlaveGroup = new System.Windows.Forms.TabControl();
     
    6867      this.scheduleView = new HeuristicLab.Clients.Hive.Administrator.Views.ScheduleView();
    6968      this.toolTip = new System.Windows.Forms.ToolTip(this.components);
    70       this.tabPermissions = new System.Windows.Forms.TabPage();
    71       this.permissionView = new HeuristicLab.Clients.Access.Views.RefreshableLightweightUserView();
    7269      ((System.ComponentModel.ISupportInitialize)(this.splitSlaves)).BeginInit();
    7370      this.splitSlaves.Panel1.SuspendLayout();
     
    7774      this.tabDetails.SuspendLayout();
    7875      this.tabSchedule.SuspendLayout();
    79       this.tabPermissions.SuspendLayout();
    8076      this.SuspendLayout();
    8177      //
     
    8884      // splitSlaves
    8985      //
    90       this.splitSlaves.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    91             | System.Windows.Forms.AnchorStyles.Left)
     86      this.splitSlaves.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
     87            | System.Windows.Forms.AnchorStyles.Left) 
    9288            | System.Windows.Forms.AnchorStyles.Right)));
    9389      this.splitSlaves.Location = new System.Drawing.Point(3, 3);
     
    9793      //
    9894      this.splitSlaves.Panel1.Controls.Add(this.btnRefresh);
    99       this.splitSlaves.Panel1.Controls.Add(this.progressBar);
    10095      this.splitSlaves.Panel1.Controls.Add(this.btnSave);
    10196      this.splitSlaves.Panel1.Controls.Add(this.btnRemoveGroup);
     
    121116      this.btnRefresh.Click += new System.EventHandler(this.btnRefresh_Click);
    122117      //
    123       // progressBar
    124       //
    125       this.progressBar.Location = new System.Drawing.Point(123, 4);
    126       this.progressBar.Name = "progressBar";
    127       this.progressBar.Size = new System.Drawing.Size(123, 23);
    128       this.progressBar.Style = System.Windows.Forms.ProgressBarStyle.Continuous;
    129       this.progressBar.TabIndex = 7;
    130       //
    131118      // btnSave
    132119      //
     
    165152      //
    166153      this.treeSlaveGroup.AllowDrop = true;
    167       this.treeSlaveGroup.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    168             | System.Windows.Forms.AnchorStyles.Left)
     154      this.treeSlaveGroup.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
     155            | System.Windows.Forms.AnchorStyles.Left) 
    169156            | System.Windows.Forms.AnchorStyles.Right)));
    170157      this.treeSlaveGroup.ImageIndex = 0;
     
    184171      // tabSlaveGroup
    185172      //
    186       this.tabSlaveGroup.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    187             | System.Windows.Forms.AnchorStyles.Left)
     173      this.tabSlaveGroup.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
     174            | System.Windows.Forms.AnchorStyles.Left) 
    188175            | System.Windows.Forms.AnchorStyles.Right)));
    189176      this.tabSlaveGroup.Controls.Add(this.tabDetails);
    190177      this.tabSlaveGroup.Controls.Add(this.tabSchedule);
    191       this.tabSlaveGroup.Controls.Add(this.tabPermissions);
    192178      this.tabSlaveGroup.Location = new System.Drawing.Point(3, 3);
    193179      this.tabSlaveGroup.Name = "tabSlaveGroup";
     
    210196      // slaveView
    211197      //
    212       this.slaveView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    213             | System.Windows.Forms.AnchorStyles.Left)
     198      this.slaveView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
     199            | System.Windows.Forms.AnchorStyles.Left) 
    214200            | System.Windows.Forms.AnchorStyles.Right)));
    215201      this.slaveView.Caption = "SlaveView";
     
    234220      // scheduleView
    235221      //
    236       this.scheduleView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    237             | System.Windows.Forms.AnchorStyles.Left)
     222      this.scheduleView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
     223            | System.Windows.Forms.AnchorStyles.Left) 
    238224            | System.Windows.Forms.AnchorStyles.Right)));
    239225      this.scheduleView.Caption = "ScheduleView";
     
    244230      this.scheduleView.Size = new System.Drawing.Size(565, 503);
    245231      this.scheduleView.TabIndex = 0;
    246       //
    247       // tabPermissions
    248       //
    249       this.tabPermissions.Controls.Add(this.btnPermissionsSave);
    250       this.tabPermissions.Controls.Add(this.permissionView);
    251       this.tabPermissions.Location = new System.Drawing.Point(4, 22);
    252       this.tabPermissions.Name = "tabPermissions";
    253       this.tabPermissions.Padding = new System.Windows.Forms.Padding(3);
    254       this.tabPermissions.Size = new System.Drawing.Size(577, 515);
    255       this.tabPermissions.TabIndex = 2;
    256       this.tabPermissions.Text = "Permissions";
    257       this.tabPermissions.UseVisualStyleBackColor = true;
    258       //
    259       // btnPermissionsSave
    260       //
    261       this.btnPermissionsSave.Enabled = false;
    262       this.btnPermissionsSave.Image = HeuristicLab.Common.Resources.VSImageLibrary.PublishToWeb;
    263       this.btnPermissionsSave.Location = new System.Drawing.Point(39, 9);
    264       this.btnPermissionsSave.Name = "btnPermissionsSave";
    265       this.btnPermissionsSave.Size = new System.Drawing.Size(24, 24);
    266       this.btnPermissionsSave.TabIndex = 1;
    267       this.toolTip.SetToolTip(this.btnPermissionsSave, "Store slave and group sharing permissions on the server");
    268       this.btnPermissionsSave.UseVisualStyleBackColor = true;
    269       this.btnPermissionsSave.Click += new System.EventHandler(this.btnPermissionsSave_Click);
    270       //
    271       // permissionView
    272       //
    273       this.permissionView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    274             | System.Windows.Forms.AnchorStyles.Left)
    275             | System.Windows.Forms.AnchorStyles.Right)));
    276       this.permissionView.Caption = "RefreshableLightweightUser View";
    277       this.permissionView.Content = null;
    278       this.permissionView.FetchSelectedUsers = null;
    279       this.permissionView.Location = new System.Drawing.Point(6, 6);
    280       this.permissionView.Name = "permissionView";
    281       this.permissionView.ReadOnly = false;
    282       this.permissionView.Size = new System.Drawing.Size(565, 503);
    283       this.permissionView.TabIndex = 0;
    284232      //
    285233      // ResourcesView
     
    297245      this.tabDetails.ResumeLayout(false);
    298246      this.tabSchedule.ResumeLayout(false);
    299       this.tabPermissions.ResumeLayout(false);
    300247      this.ResumeLayout(false);
    301248
     
    315262    private ScheduleView scheduleView;
    316263    private System.Windows.Forms.Button btnSave;
    317     private System.Windows.Forms.ProgressBar progressBar;
    318264    private System.Windows.Forms.Button btnRefresh;
    319265    private System.Windows.Forms.ToolTip toolTip;
    320     private System.Windows.Forms.TabPage tabPermissions;
    321     private Access.Views.RefreshableLightweightUserView permissionView;
    322     private System.Windows.Forms.Button btnPermissionsSave;
    323266  }
    324267}
  • branches/HiveProjectManagement/HeuristicLab.Clients.Hive.Administrator/3.3/Views/ResourcesView.cs

    r14185 r15401  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2121
    2222using System;
    23 using System.Collections.Generic;
     23using System.ComponentModel;
    2424using System.Drawing;
    2525using System.Linq;
    26 using System.ServiceModel.Security;
    27 using System.Threading;
    28 using System.Threading.Tasks;
    2926using System.Windows.Forms;
    3027using HeuristicLab.Clients.Access;
    3128using HeuristicLab.Clients.Hive.Views;
     29using HeuristicLab.Common.Resources;
    3230using HeuristicLab.Core;
    3331using HeuristicLab.Core.Views;
    3432using HeuristicLab.MainForm;
    35 using TS = System.Threading.Tasks;
    3633
    3734namespace HeuristicLab.Clients.Hive.Administrator.Views {
     
    3936  [Content(typeof(IItemList<Resource>), false)]
    4037  public partial class ResourcesView : ItemView, IDisposable {
     38    private const string UngroupedGroupName = "UNGROUPED";
     39    private const int slaveImageIndex = 0;
     40    private const int slaveGroupImageIndex = 1;
     41
     42    private readonly Color ownedResourceColor = Color.LightGreen;
     43    private readonly object locker = new object();
     44    private bool updatingResources = false;
     45    private bool removingResources = false;
     46    private bool savingResources = false;
     47
    4148    public new IItemList<Resource> Content {
    4249      get { return (IItemList<Resource>)base.Content; }
     
    4451    }
    4552
    46     public const string UngroupedGroupName = "UNGROUPED";
    47     private const int slaveImageIndex = 0;
    48     private const int slaveGroupImageIndex = 1;
    49     private readonly Color ownedResourceColor = Color.LightGreen;
    50     private TS.Task progressTask;
    51     private bool stopProgressTask;
    52     private bool currentlyAuthorized;
    53 
    54 
    5553    public ResourcesView() {
    5654      InitializeComponent();
    57       treeSlaveGroup.ImageList.Images.Add(HeuristicLab.Common.Resources.VSImageLibrary.MonitorLarge);
    58       treeSlaveGroup.ImageList.Images.Add(HeuristicLab.Common.Resources.VSImageLibrary.NetworkCenterLarge);
    59 
    60       HiveAdminClient.Instance.Refreshing += new EventHandler(Instance_Refreshing);
    61       HiveAdminClient.Instance.Refreshed += new EventHandler(Instance_Refreshed);
    62 
    63       Access.AccessClient.Instance.Refreshing += new EventHandler(AccessClient_Refreshing);
    64       Access.AccessClient.Instance.Refreshed += new EventHandler(AccessClient_Refreshed);
    65     }
    66 
    67     private void UpdateProgress() {
    68       while (!stopProgressTask) {
    69         int diff = (progressBar.Maximum - progressBar.Minimum) / 10;
    70 
    71         if (progressBar.InvokeRequired) {
    72           progressBar.Invoke(new Action(delegate() { progressBar.Value = (progressBar.Value + diff) % progressBar.Maximum; }));
    73         } else {
    74           progressBar.Value = (progressBar.Value + diff) % progressBar.Maximum;
    75         }
    76 
    77         //ok, this is not very clever...
    78         Thread.Sleep(500);
    79       }
    80       if (progressBar.InvokeRequired) {
    81         progressBar.Invoke(new Action(delegate() { progressBar.Value = progressBar.Minimum; }));
    82       } else {
    83         progressBar.Value = progressBar.Minimum;
    84       }
    85     }
    86 
    87     void Instance_Refreshing(object sender, EventArgs e) {
    88       stopProgressTask = false;
    89       progressTask = new TS.Task(UpdateProgress);
    90       progressTask.Start();
    91       SetEnabledStateOfControls();
    92     }
    93 
    94     void Instance_Refreshed(object sender, EventArgs e) {
    95       stopProgressTask = true;
    96       SetEnabledStateOfControls();
    97     }
    98 
    99     void AccessClient_Refreshing(object sender, EventArgs e) {
    100       stopProgressTask = false;
    101       progressTask = new TS.Task(UpdateProgress);
    102       progressTask.Start();
    103       SetEnabledStateOfControls();
    104       btnPermissionsSave.Enabled = false;
    105     }
    106 
    107     void AccessClient_Refreshed(object sender, EventArgs e) {
    108       stopProgressTask = true;
    109       SetEnabledStateOfControls();
    110     }
    111 
    112     #region Register Content Events
    113     protected override void DeregisterContentEvents() {
    114       Content.ItemsAdded -= new Collections.CollectionItemsChangedEventHandler<Collections.IndexedItem<Resource>>(Content_ItemsAdded);
    115       Content.ItemsRemoved -= new Collections.CollectionItemsChangedEventHandler<Collections.IndexedItem<Resource>>(Content_ItemsRemoved);
    116       base.DeregisterContentEvents();
    117     }
     55
     56      treeSlaveGroup.ImageList.Images.Add(VSImageLibrary.MonitorLarge);
     57      treeSlaveGroup.ImageList.Images.Add(VSImageLibrary.NetworkCenterLarge);
     58
     59      HiveAdminClient.Instance.Refreshing += HiveAdminClient_Instance_Refreshing;
     60      HiveAdminClient.Instance.Refreshed += HiveAdminClient_Instance_Refreshed;
     61      AccessClient.Instance.Refreshing += AccessClient_Instance_Refreshing;
     62      AccessClient.Instance.Refreshed += AccessClient_Instance_Refreshed;
     63    }
     64
     65    #region Overrides
     66    protected override void OnClosing(FormClosingEventArgs e) {
     67      AccessClient.Instance.Refreshed -= AccessClient_Instance_Refreshed;
     68      AccessClient.Instance.Refreshing -= AccessClient_Instance_Refreshing;
     69      HiveAdminClient.Instance.Refreshed -= HiveAdminClient_Instance_Refreshed;
     70      HiveAdminClient.Instance.Refreshing -= HiveAdminClient_Instance_Refreshing;
     71      base.OnClosing(e);
     72    }
     73
    11874    protected override void RegisterContentEvents() {
    11975      base.RegisterContentEvents();
    120       Content.ItemsAdded += new Collections.CollectionItemsChangedEventHandler<Collections.IndexedItem<Resource>>(Content_ItemsAdded);
    121       Content.ItemsRemoved += new Collections.CollectionItemsChangedEventHandler<Collections.IndexedItem<Resource>>(Content_ItemsRemoved);
    122     }
    123     #endregion
     76      Content.ItemsAdded += Content_ItemsAdded;
     77      Content.ItemsRemoved += Content_ItemsRemoved;
     78    }
     79
     80    protected override void DeregisterContentEvents() {
     81      Content.ItemsRemoved -= Content_ItemsRemoved;
     82      Content.ItemsAdded -= Content_ItemsAdded;
     83      base.DeregisterContentEvents();
     84    }
    12485
    12586    protected override void OnContentChanged() {
     
    12889        slaveView.Content = null;
    12990        scheduleView.Content = null;
    130         permissionView.Content = null;
    131         permissionView.FetchSelectedUsers = null;
    13291        treeSlaveGroup.Nodes.Clear();
    13392      } else {
    134         permissionView.Content = Access.AccessClient.Instance;
    13593        treeSlaveGroup.Nodes.Clear();
    13694
     
    145103        ungrp.Tag = newGroup;
    146104
    147         foreach (Resource g in Content) {
     105        foreach (Resource g in Content.OrderBy(x => x.Name)) {
    148106          if (g.GetType() == typeof(SlaveGroup)) {
    149107            //root node
     
    175133    }
    176134
    177     private void BuildSlaveGroupTree(Resource g, TreeNode tn) {
    178       foreach (Resource r in Content.Where(s => s.ParentResourceId != null && s.ParentResourceId == g.Id)) {
    179         TreeNode stn = new TreeNode(r.Name);
    180         if (r is Slave) {
    181           stn.ImageIndex = slaveImageIndex;
    182         } else if (r is SlaveGroup) {
    183           stn.ImageIndex = slaveGroupImageIndex;
    184         }
    185         stn.SelectedImageIndex = stn.ImageIndex;
    186         stn.Tag = r;
    187         if (r.OwnerUserId == Access.UserInformation.Instance.User.Id) stn.BackColor = ownedResourceColor;
    188         tn.Nodes.Add(stn);
    189 
    190         BuildSlaveGroupTree(r, stn);
    191       }
    192     }
    193 
    194135    protected override void SetEnabledStateOfControls() {
    195136      base.SetEnabledStateOfControls();
    196       if (Content == null) {
    197         btnAddGroup.Enabled = false;
    198         btnRemoveGroup.Enabled = false;
    199         btnSave.Enabled = false;
    200         btnPermissionsSave.Enabled = false;
    201         permissionView.Enabled = false;
    202         scheduleView.SetEnabledStateOfSchedule(false);
    203         btnPermissionsSave.Enabled = false;
    204         permissionView.Enabled = false;
    205       } else {
    206         btnAddGroup.Enabled = true;
    207         btnRemoveGroup.Enabled = true;
    208         btnSave.Enabled = true;
    209         scheduleView.SetEnabledStateOfSchedule(IsAuthorized(slaveView.Content));
    210         btnPermissionsSave.Enabled = permissionView.FetchSelectedUsers != null;
    211         permissionView.Enabled = permissionView.FetchSelectedUsers != null;
    212       }
    213     }
    214 
    215     private bool IsAuthorized(Resource resource) {
    216       return resource != null
    217           && resource.Name != UngroupedGroupName
    218           && resource.Id != Guid.Empty
    219           && UserInformation.Instance.UserExists
    220           && (resource.OwnerUserId == UserInformation.Instance.User.Id || HiveRoles.CheckAdminUserPermissions());
    221     }
    222 
    223     private void treeSlaveGroup_AfterSelect(object sender, TreeViewEventArgs e) {
    224       if (e.Action != TreeViewAction.Unknown) {
    225         Resource selectedResource = ((Resource)e.Node.Tag);
    226         currentlyAuthorized = IsAuthorized(selectedResource);
    227         if (currentlyAuthorized) {
    228           permissionView.FetchSelectedUsers = new Func<List<Guid>>(() => {
    229             return HiveServiceLocator.Instance.CallHiveService<List<ResourcePermission>>(service => {
    230               return service.GetResourcePermissions(selectedResource.Id);
    231             }).Select(x => x.GrantedUserId).ToList();
    232           });
    233           if (!tabSlaveGroup.TabPages.Contains(tabPermissions)) tabSlaveGroup.TabPages.Add(tabPermissions);
    234         } else {
    235           permissionView.FetchSelectedUsers = null;
    236           btnPermissionsSave.Enabled = false;
    237           if (selectedResource.Id == Guid.Empty) {
    238             if (!tabSlaveGroup.TabPages.Contains(tabPermissions)) tabSlaveGroup.TabPages.Add(tabPermissions);
    239           } else tabSlaveGroup.TabPages.Remove(tabPermissions);
    240         }
    241 
    242         if (slaveView.Content != null && slaveView.Content is SlaveGroup) {
    243           slaveView.Content.PropertyChanged -= new System.ComponentModel.PropertyChangedEventHandler(SlaveViewContent_PropertyChanged);
    244         }
    245 
    246         slaveView.Content = selectedResource;
    247         HiveAdminClient.Instance.DowntimeForResourceId = selectedResource.Id;
    248 
    249         if (selectedResource is SlaveGroup) {
    250           slaveView.Content.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(SlaveViewContent_PropertyChanged);
    251         }
    252 
    253         if (tabSlaveGroup.SelectedIndex == 1) {
    254           UpdateScheduleAsync();
    255         } else if (tabSlaveGroup.SelectedIndex == 2) {
    256           UpdatePermissionsAsync();
    257         }
    258       }
    259     }
    260 
    261     void SlaveViewContent_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) {
     137      bool enabled = Content != null;
     138      btnAddGroup.Enabled = enabled;
     139      btnRemoveGroup.Enabled = enabled;
     140      btnSave.Enabled = enabled;
     141      scheduleView.SetEnabledStateOfSchedule(enabled && IsAuthorized(slaveView.Content));
     142    }
     143    #endregion
     144
     145    #region Event Handlers
     146    private void Content_ItemsAdded(object sender, Collections.CollectionItemsChangedEventArgs<Collections.IndexedItem<Resource>> e) {
     147      OnContentChanged();
     148    }
     149
     150    private void Content_ItemsRemoved(object sender, Collections.CollectionItemsChangedEventArgs<Collections.IndexedItem<Resource>> e) {
     151      OnContentChanged();
     152    }
     153
     154    private void SlaveViewContent_PropertyChanged(object sender, PropertyChangedEventArgs e) {
    262155      OnContentChanged();
    263156      if (e.PropertyName == "HbInterval") {
     
    266159    }
    267160
    268     private void UpdateChildHbIntervall(Resource resource) {
    269       foreach (Resource r in Content.Where(x => x.ParentResourceId == resource.Id)) {
    270         r.HbInterval = resource.HbInterval;
    271         if (r is SlaveGroup) {
    272           UpdateChildHbIntervall(r);
    273         }
    274       }
     161    private void HiveAdminClient_Instance_Refreshing(object sender, EventArgs e) {
     162      if (InvokeRequired) Invoke((Action<object, EventArgs>)HiveAdminClient_Instance_Refreshing, sender, e);
     163      else {
     164        var mainForm = MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>();
     165        mainForm.AddOperationProgressToView(this, "Refreshing ...");
     166        SetEnabledStateOfControls();
     167      }
     168    }
     169
     170    private void HiveAdminClient_Instance_Refreshed(object sender, EventArgs e) {
     171      if (InvokeRequired) Invoke((Action<object, EventArgs>)HiveAdminClient_Instance_Refreshed, sender, e);
     172      else {
     173        var mainForm = MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>();
     174        mainForm.RemoveOperationProgressFromView(this);
     175        SetEnabledStateOfControls();
     176      }
     177    }
     178
     179    private void AccessClient_Instance_Refreshing(object sender, EventArgs e) {
     180      if (InvokeRequired) Invoke((Action<object, EventArgs>)AccessClient_Instance_Refreshing, sender, e);
     181      else {
     182        var mainForm = MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>();
     183        mainForm.AddOperationProgressToView(this, "Refreshing ...");
     184        SetEnabledStateOfControls();
     185      }
     186    }
     187
     188    private void AccessClient_Instance_Refreshed(object sender, EventArgs e) {
     189      if (InvokeRequired) Invoke((Action<object, EventArgs>)AccessClient_Instance_Refreshed, sender, e);
     190      else {
     191        var mainForm = MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>();
     192        mainForm.RemoveOperationProgressFromView(this);
     193        SetEnabledStateOfControls();
     194      }
     195    }
     196
     197    private async void ResourcesView_Load(object sender, EventArgs e) {
     198      lock (locker) {
     199        if (updatingResources) return;
     200        updatingResources = true;
     201      }
     202
     203      await SecurityExceptionUtil.TryAsyncAndReportSecurityExceptions(
     204        action: () => UpdateResources(),
     205        finallyCallback: () => updatingResources = false);
     206    }
     207
     208    private async void btnRefresh_Click(object sender, EventArgs e) {
     209      lock (locker) {
     210        if (updatingResources) return;
     211        updatingResources = true;
     212      }
     213
     214      await SecurityExceptionUtil.TryAsyncAndReportSecurityExceptions(
     215        action: () => UpdateResources(),
     216        finallyCallback: () => updatingResources = false);
    275217    }
    276218
    277219    private void btnAddGroup_Click(object sender, EventArgs e) {
    278       SlaveGroup newGroup = new SlaveGroup();
    279       newGroup.Name = "New Group";
    280       newGroup.OwnerUserId = UserInformation.Instance.User.Id;
    281       Content.Add(newGroup);
    282     }
    283 
    284     void Content_ItemsRemoved(object sender, Collections.CollectionItemsChangedEventArgs<Collections.IndexedItem<Resource>> e) {
    285       OnContentChanged();
    286     }
    287 
    288     void Content_ItemsAdded(object sender, Collections.CollectionItemsChangedEventArgs<Collections.IndexedItem<Resource>> e) {
    289       OnContentChanged();
    290     }
    291 
    292     private void btnRemoveGroup_Click(object sender, EventArgs e) {
    293       if (treeSlaveGroup.SelectedNode != null && treeSlaveGroup.SelectedNode.Tag != null) {
    294         Resource res = (Resource)treeSlaveGroup.SelectedNode.Tag;
    295 
    296         DialogResult diagRes = MessageBox.Show("Do you really want to delete " + res.Name + "?", "HeuristicLab Hive Administrator", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
    297         if (diagRes == DialogResult.Yes) {
    298           if (res is Slave) {
    299             Content.Remove(res);
    300             HiveAdminClient.Delete(res);
    301           } else if (res is SlaveGroup) {
    302             //only delete empty groups
    303             if (Content.Where(s => s.ParentResourceId == res.Id).Count() < 1) {
    304               Content.Remove(res);
    305               HiveAdminClient.Delete(res);
    306             } else {
    307               MessageBox.Show("Only empty groups can be deleted.", "HeuristicLab Hive Administrator", MessageBoxButtons.OK, MessageBoxIcon.Error);
    308             }
    309           }
    310         }
    311       }
    312     }
    313 
    314     private void btnSave_Click(object sender, EventArgs e) {
    315       foreach (Resource res in Content) {
    316         if (res is SlaveGroup && res.Id == Guid.Empty) {
    317           SlaveGroup slaveGroup = (SlaveGroup)res;
    318           slaveGroup.Store();
    319         } else if (res.Id != Guid.Empty && res.Modified) {
    320           res.Store();
    321         }
    322       }
     220      var group = new SlaveGroup {
     221        Name = "New Group",
     222        OwnerUserId = UserInformation.Instance.User.Id
     223      };
     224      Content.Add(group);
     225    }
     226
     227    private async void btnRemoveGroup_Click(object sender, EventArgs e) {
     228      lock (locker) {
     229        if (removingResources) return;
     230        removingResources = true;
     231      }
     232
     233      await SecurityExceptionUtil.TryAsyncAndReportSecurityExceptions(
     234        action: () => RemoveResource(),
     235        finallyCallback: () => removingResources = false);
     236    }
     237
     238    private async void btnSave_Click(object sender, EventArgs e) {
     239      lock (locker) {
     240        if (savingResources) return;
     241        savingResources = true;
     242      }
     243
     244      await SecurityExceptionUtil.TryAsyncAndReportSecurityExceptions(
     245        action: () => {
     246          var resourcesToSave = Content.Where(x => x.Id == Guid.Empty || x.Modified);
     247          foreach (var resource in resourcesToSave)
     248            resource.Store();
     249        },
     250        finallyCallback: () => savingResources = false);
     251    }
     252
     253    private async void treeSlaveGroup_AfterSelect(object sender, TreeViewEventArgs e) {
     254      var selectedResource = (Resource)e.Node.Tag;
     255
     256      if (slaveView.Content != null && slaveView.Content is SlaveGroup)
     257        slaveView.Content.PropertyChanged -= SlaveViewContent_PropertyChanged;
     258
     259      slaveView.Content = selectedResource;
     260
     261      if (selectedResource is SlaveGroup)
     262        slaveView.Content.PropertyChanged += SlaveViewContent_PropertyChanged;
     263
     264      await SecurityExceptionUtil.TryAsyncAndReportSecurityExceptions(
     265        action: () => UpdateSchedule());
    323266    }
    324267
     
    386329    }
    387330
    388     private bool CheckParentsEqualsMovedNode(TreeNode dest, TreeNode movedNode) {
    389       TreeNode tmp = dest;
    390 
    391       while (tmp != null) {
    392         if (tmp == movedNode) {
    393           return true;
    394         }
    395         tmp = tmp.Parent;
    396       }
    397       return false;
    398     }
    399 
    400331    private void treeSlaveGroup_ItemDrag(object sender, ItemDragEventArgs e) {
    401332      TreeNode sourceNode = (TreeNode)e.Item;
     
    416347    }
    417348
    418     void ResetView() {
    419       if (this.InvokeRequired) {
    420         Invoke(new Action(ResetView));
    421       } else {
     349    private void tabSlaveGroup_SelectedIndexChanged(object sender, EventArgs e) {
     350      if (tabSlaveGroup.SelectedIndex == 1) {
     351        UpdateSchedule();
     352      }
     353    }
     354    #endregion
     355
     356    #region Helpers
     357    private void BuildSlaveGroupTree(Resource g, TreeNode tn) {
     358      foreach (Resource r in Content.Where(s => s.ParentResourceId != null && s.ParentResourceId == g.Id).OrderBy(x => x.Name)) {
     359        TreeNode stn = new TreeNode(r.Name);
     360        if (r is Slave) {
     361          stn.ImageIndex = slaveImageIndex;
     362        } else if (r is SlaveGroup) {
     363          stn.ImageIndex = slaveGroupImageIndex;
     364        }
     365        stn.SelectedImageIndex = stn.ImageIndex;
     366        stn.Tag = r;
     367        if (r.OwnerUserId == Access.UserInformation.Instance.User.Id) stn.BackColor = ownedResourceColor;
     368        tn.Nodes.Add(stn);
     369
     370        BuildSlaveGroupTree(r, stn);
     371      }
     372    }
     373
     374    private void UpdateChildHbIntervall(Resource resource) {
     375      foreach (Resource r in Content.Where(x => x.ParentResourceId == resource.Id)) {
     376        r.HbInterval = resource.HbInterval;
     377        if (r is SlaveGroup) {
     378          UpdateChildHbIntervall(r);
     379        }
     380      }
     381    }
     382
     383    private bool CheckParentsEqualsMovedNode(TreeNode dest, TreeNode movedNode) {
     384      TreeNode tmp = dest;
     385
     386      while (tmp != null) {
     387        if (tmp == movedNode) {
     388          return true;
     389        }
     390        tmp = tmp.Parent;
     391      }
     392      return false;
     393    }
     394
     395    private void ResetView() {
     396      if (InvokeRequired) Invoke((Action)ResetView);
     397      else {
    422398        treeSlaveGroup.Nodes.Clear();
    423399
    424400        if (slaveView.Content != null && slaveView.Content is SlaveGroup) {
    425           slaveView.Content.PropertyChanged -= new System.ComponentModel.PropertyChangedEventHandler(SlaveViewContent_PropertyChanged);
    426         }
     401          slaveView.Content.PropertyChanged -= SlaveViewContent_PropertyChanged;
     402        }
     403
    427404        slaveView.Content = null;
    428405        if (scheduleView.Content != null) {
    429406          scheduleView.Content.Clear();
    430407        }
     408
    431409        HiveAdminClient.Instance.ResetDowntime();
    432410      }
     
    434412
    435413    private void UpdateResources() {
    436       ResetView();
    437 
    438414      try {
    439         if (!Access.UserInformation.Instance.UserExists) {
    440           //do a refresh just in case that the user has changed his usr and pwd in between
    441           Access.UserInformation.Instance.Refresh();
    442         }
     415        ResetView();
    443416        HiveAdminClient.Instance.Refresh();
    444417        Content = HiveAdminClient.Instance.Resources;
    445       }
    446       catch (MessageSecurityException) {
    447         ShowMessageSecurityException();
    448       }
    449       catch (AnonymousUserException) {
     418      } catch (AnonymousUserException) {
    450419        ShowHiveInformationDialog();
    451420      }
    452421    }
    453422
    454     private void ShowMessageSecurityException() {
    455       if (this.InvokeRequired) {
    456         Invoke(new Action(ShowMessageSecurityException));
     423    private void RemoveResource() {
     424      var selectedNode = treeSlaveGroup.SelectedNode;
     425      if (selectedNode == null || selectedNode.Tag == null) return;
     426
     427      var resource = (Resource)selectedNode.Tag;
     428      var result = MessageBox.Show(
     429        "Do you really want to delete " + resource.Name + "?",
     430        "HeuristicLab Hive Administrator",
     431        MessageBoxButtons.YesNo,
     432        MessageBoxIcon.Question);
     433
     434      if (result == DialogResult.Yes) {
     435        if (resource is Slave) {
     436          Content.Remove(resource);
     437          HiveAdminClient.Delete(resource);
     438        } else if (resource is SlaveGroup) {
     439          if (Content.Any(x => x.ParentResourceId == resource.Id)) {
     440            MessageBox.Show(
     441              "Only empty resources can be deleted.",
     442              "HeuristicLab Hive Administrator",
     443              MessageBoxButtons.OK,
     444              MessageBoxIcon.Error);
     445          } else {
     446            Content.Remove(resource);
     447            HiveAdminClient.Delete(resource);
     448          }
     449        }
     450      }
     451    }
     452
     453    private void UpdateSchedule() {
     454      var selectedNode = treeSlaveGroup.SelectedNode;
     455      var resource = (Resource)selectedNode?.Tag;
     456
     457      if (IsAuthorized(resource)) {
     458        if (!tabSlaveGroup.TabPages.Contains(tabSchedule))
     459          tabSlaveGroup.TabPages.Add(tabSchedule);
     460
     461        if (tabSlaveGroup.SelectedIndex == 1) {
     462          HiveAdminClient.Instance.DowntimeForResourceId = resource.Id;
     463          HiveAdminClient.Instance.RefreshCalendar();
     464          scheduleView.Invoke((Action)(() => {
     465            scheduleView.Content = HiveAdminClient.Instance.Downtimes;
     466            SetEnabledStateOfControls();
     467          }));
     468        }
    457469      } else {
    458         MessageBox.Show("A Message Security error has occured. This normally means that your user name or password is wrong.", "HeuristicLab Hive Administrator", MessageBoxButtons.OK, MessageBoxIcon.Error);
    459       }
     470        if (tabSlaveGroup.TabPages.Contains(tabSchedule))
     471          tabSlaveGroup.TabPages.Remove(tabSchedule);
     472      }
     473    }
     474
     475    private bool IsAuthorized(Resource resource) {
     476      return resource != null
     477          && resource.Name != UngroupedGroupName
     478          && resource.Id != Guid.Empty
     479          && UserInformation.Instance.UserExists
     480          && (resource.OwnerUserId == UserInformation.Instance.User.Id || HiveRoles.CheckAdminUserPermissions());
    460481    }
    461482
    462483    private void ShowHiveInformationDialog() {
    463       if (this.InvokeRequired) {
    464         Invoke(new Action(ShowHiveInformationDialog));
    465       } else {
     484      if (InvokeRequired) Invoke((Action)ShowHiveInformationDialog);
     485      else {
    466486        using (HiveInformationDialog dialog = new HiveInformationDialog()) {
    467487          dialog.ShowDialog(this);
     
    469489      }
    470490    }
    471 
    472     private void UpdateResourcesAsync() {
    473       TS.Task.Factory.StartNew(UpdateResources).ContinueWith((t) => {
    474         DisplayError(t.Exception);
    475       }, TaskContinuationOptions.OnlyOnFaulted);
    476     }
    477 
    478     private void UpdateSchedule() {
    479       HiveAdminClient.Instance.RefreshCalendar();
    480       scheduleView.Invoke(new Action(() => {
    481         scheduleView.Content = HiveAdminClient.Instance.Downtimes;
    482         SetEnabledStateOfControls();
    483       }));
    484     }
    485 
    486     private void UpdateScheduleAsync() {
    487       TS.Task.Factory.StartNew(UpdateSchedule).ContinueWith((t) => {
    488         DisplayError(t.Exception);
    489       }, TaskContinuationOptions.OnlyOnFaulted);
    490     }
    491 
    492     private void UpdatePermissions() {
    493       if (permissionView.Content != null && permissionView.FetchSelectedUsers != null)
    494         permissionView.Invoke(new Action(() => permissionView.ManualRefresh()));
    495     }
    496 
    497     private void UpdatePermissionsAsync() {
    498       TS.Task.Factory.StartNew(UpdatePermissions).ContinueWith((t) => {
    499         DisplayError(t.Exception);
    500       }, TaskContinuationOptions.OnlyOnFaulted);
    501     }
    502 
    503 
    504     private void DisplayError(Exception ex) {
    505       MessageBox.Show(string.Format("An error occured while updating: {0} {1}", Environment.NewLine, ex.Message), "HeuristicLab Hive Administrator", MessageBoxButtons.OK, MessageBoxIcon.Error);
    506     }
    507 
    508     private void tabSlaveGroup_SelectedIndexChanged(object sender, EventArgs e) {
    509       if (tabSlaveGroup.SelectedIndex == 1) {
    510         UpdateScheduleAsync();
    511       } else if (tabSlaveGroup.SelectedIndex == 2) {
    512         UpdatePermissionsAsync();
    513       }
    514     }
    515 
    516     private void btnRefresh_Click(object sender, EventArgs e) {
    517       UpdateResourcesAsync();
    518     }
    519 
    520     private void ResourcesView_Load(object sender, EventArgs e) {
    521       UpdateResourcesAsync();
    522     }
    523 
    524     private void btnPermissionsSave_Click(object sender, EventArgs e) {
    525       SetEnabledStateOfControls();
    526       HiveServiceLocator.Instance.CallHiveService(service => {
    527         service.GrantResourcePermissions(((Resource)treeSlaveGroup.SelectedNode.Tag).Id, permissionView.GetAddedUsers().Select(x => x.Id).ToList());
    528         service.RevokeResourcePermissions(((Resource)treeSlaveGroup.SelectedNode.Tag).Id, permissionView.GetDeletedUsers().Select(x => x.Id).ToList());
    529       });
    530       SetEnabledStateOfControls();
    531     }
     491    #endregion
    532492  }
    533493}
Note: See TracChangeset for help on using the changeset viewer.