Changeset 15401 for branches/HiveProjectManagement/HeuristicLab.Clients.Hive.Administrator/3.3/Views
- Timestamp:
- 10/04/17 13:56:38 (7 years ago)
- 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 30 30 this.tabAdmin = new System.Windows.Forms.TabControl(); 31 31 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(); 32 34 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(); 34 36 this.tabAdmin.SuspendLayout(); 35 37 this.tabSlaves.SuspendLayout(); 38 this.tabPage1.SuspendLayout(); 36 39 this.SuspendLayout(); 37 40 // 38 41 // tabAdmin 39 42 // 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 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))); 43 46 this.tabAdmin.Controls.Add(this.tabSlaves); 47 this.tabAdmin.Controls.Add(this.tabPage1); 44 48 this.tabAdmin.Location = new System.Drawing.Point(3, 0); 45 49 this.tabAdmin.Name = "tabAdmin"; … … 59 63 this.tabSlaves.UseVisualStyleBackColor = true; 60 64 // 61 // imageListUsers62 //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 //67 65 // resourcesView 68 66 // 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 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))); 72 70 this.resourcesView.Caption = "ResourcesView"; 73 71 this.resourcesView.Content = null; … … 78 76 this.resourcesView.TabIndex = 0; 79 77 // 80 // HiveAdministrationView78 // tabPage1 81 79 // 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 // 83 109 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit; 84 110 this.Controls.Add(this.tabAdmin); 85 this.Name = "HiveAdministrat ionView";111 this.Name = "HiveAdministratorView"; 86 112 this.Size = new System.Drawing.Size(745, 546); 87 113 this.tabAdmin.ResumeLayout(false); 88 114 this.tabSlaves.ResumeLayout(false); 115 this.tabPage1.ResumeLayout(false); 89 116 this.ResumeLayout(false); 90 117 … … 96 123 private System.Windows.Forms.ImageList imageListUsers; 97 124 private System.Windows.Forms.TabPage tabSlaves; 98 125 private System.Windows.Forms.TabPage tabPage1; 126 private ProjectsView projectsView; 99 127 } 100 128 } -
branches/HiveProjectManagement/HeuristicLab.Clients.Hive.Administrator/3.3/Views/ResourcesView.Designer.cs
r14185 r15401 37 37 components.Dispose(); 38 38 } 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); 44 44 base.Dispose(disposing); 45 45 } … … 53 53 private void InitializeComponent() { 54 54 this.components = new System.ComponentModel.Container(); 55 System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ResourcesView)); 55 56 this.imageListSlaveGroups = new System.Windows.Forms.ImageList(this.components); 56 57 this.splitSlaves = new System.Windows.Forms.SplitContainer(); 57 58 this.btnRefresh = new System.Windows.Forms.Button(); 58 this.progressBar = new System.Windows.Forms.ProgressBar();59 59 this.btnSave = new System.Windows.Forms.Button(); 60 60 this.btnRemoveGroup = new System.Windows.Forms.Button(); 61 61 this.btnAddGroup = new System.Windows.Forms.Button(); 62 this.btnPermissionsSave = new System.Windows.Forms.Button();63 62 this.treeSlaveGroup = new System.Windows.Forms.TreeView(); 64 63 this.tabSlaveGroup = new System.Windows.Forms.TabControl(); … … 68 67 this.scheduleView = new HeuristicLab.Clients.Hive.Administrator.Views.ScheduleView(); 69 68 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();72 69 ((System.ComponentModel.ISupportInitialize)(this.splitSlaves)).BeginInit(); 73 70 this.splitSlaves.Panel1.SuspendLayout(); … … 77 74 this.tabDetails.SuspendLayout(); 78 75 this.tabSchedule.SuspendLayout(); 79 this.tabPermissions.SuspendLayout();80 76 this.SuspendLayout(); 81 77 // … … 88 84 // splitSlaves 89 85 // 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) 92 88 | System.Windows.Forms.AnchorStyles.Right))); 93 89 this.splitSlaves.Location = new System.Drawing.Point(3, 3); … … 97 93 // 98 94 this.splitSlaves.Panel1.Controls.Add(this.btnRefresh); 99 this.splitSlaves.Panel1.Controls.Add(this.progressBar);100 95 this.splitSlaves.Panel1.Controls.Add(this.btnSave); 101 96 this.splitSlaves.Panel1.Controls.Add(this.btnRemoveGroup); … … 121 116 this.btnRefresh.Click += new System.EventHandler(this.btnRefresh_Click); 122 117 // 123 // progressBar124 //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 //131 118 // btnSave 132 119 // … … 165 152 // 166 153 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) 169 156 | System.Windows.Forms.AnchorStyles.Right))); 170 157 this.treeSlaveGroup.ImageIndex = 0; … … 184 171 // tabSlaveGroup 185 172 // 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) 188 175 | System.Windows.Forms.AnchorStyles.Right))); 189 176 this.tabSlaveGroup.Controls.Add(this.tabDetails); 190 177 this.tabSlaveGroup.Controls.Add(this.tabSchedule); 191 this.tabSlaveGroup.Controls.Add(this.tabPermissions);192 178 this.tabSlaveGroup.Location = new System.Drawing.Point(3, 3); 193 179 this.tabSlaveGroup.Name = "tabSlaveGroup"; … … 210 196 // slaveView 211 197 // 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) 214 200 | System.Windows.Forms.AnchorStyles.Right))); 215 201 this.slaveView.Caption = "SlaveView"; … … 234 220 // scheduleView 235 221 // 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) 238 224 | System.Windows.Forms.AnchorStyles.Right))); 239 225 this.scheduleView.Caption = "ScheduleView"; … … 244 230 this.scheduleView.Size = new System.Drawing.Size(565, 503); 245 231 this.scheduleView.TabIndex = 0; 246 //247 // tabPermissions248 //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 // btnPermissionsSave260 //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 // permissionView272 //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;284 232 // 285 233 // ResourcesView … … 297 245 this.tabDetails.ResumeLayout(false); 298 246 this.tabSchedule.ResumeLayout(false); 299 this.tabPermissions.ResumeLayout(false);300 247 this.ResumeLayout(false); 301 248 … … 315 262 private ScheduleView scheduleView; 316 263 private System.Windows.Forms.Button btnSave; 317 private System.Windows.Forms.ProgressBar progressBar;318 264 private System.Windows.Forms.Button btnRefresh; 319 265 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;323 266 } 324 267 } -
branches/HiveProjectManagement/HeuristicLab.Clients.Hive.Administrator/3.3/Views/ResourcesView.cs
r14185 r15401 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 6Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 21 21 22 22 using System; 23 using System.Co llections.Generic;23 using System.ComponentModel; 24 24 using System.Drawing; 25 25 using System.Linq; 26 using System.ServiceModel.Security;27 using System.Threading;28 using System.Threading.Tasks;29 26 using System.Windows.Forms; 30 27 using HeuristicLab.Clients.Access; 31 28 using HeuristicLab.Clients.Hive.Views; 29 using HeuristicLab.Common.Resources; 32 30 using HeuristicLab.Core; 33 31 using HeuristicLab.Core.Views; 34 32 using HeuristicLab.MainForm; 35 using TS = System.Threading.Tasks;36 33 37 34 namespace HeuristicLab.Clients.Hive.Administrator.Views { … … 39 36 [Content(typeof(IItemList<Resource>), false)] 40 37 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 41 48 public new IItemList<Resource> Content { 42 49 get { return (IItemList<Resource>)base.Content; } … … 44 51 } 45 52 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 55 53 public ResourcesView() { 56 54 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 118 74 protected override void RegisterContentEvents() { 119 75 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 } 124 85 125 86 protected override void OnContentChanged() { … … 128 89 slaveView.Content = null; 129 90 scheduleView.Content = null; 130 permissionView.Content = null;131 permissionView.FetchSelectedUsers = null;132 91 treeSlaveGroup.Nodes.Clear(); 133 92 } else { 134 permissionView.Content = Access.AccessClient.Instance;135 93 treeSlaveGroup.Nodes.Clear(); 136 94 … … 145 103 ungrp.Tag = newGroup; 146 104 147 foreach (Resource g in Content ) {105 foreach (Resource g in Content.OrderBy(x => x.Name)) { 148 106 if (g.GetType() == typeof(SlaveGroup)) { 149 107 //root node … … 175 133 } 176 134 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 194 135 protected override void SetEnabledStateOfControls() { 195 136 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) { 262 155 OnContentChanged(); 263 156 if (e.PropertyName == "HbInterval") { … … 266 159 } 267 160 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); 275 217 } 276 218 277 219 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()); 323 266 } 324 267 … … 386 329 } 387 330 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 400 331 private void treeSlaveGroup_ItemDrag(object sender, ItemDragEventArgs e) { 401 332 TreeNode sourceNode = (TreeNode)e.Item; … … 416 347 } 417 348 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 { 422 398 treeSlaveGroup.Nodes.Clear(); 423 399 424 400 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 427 404 slaveView.Content = null; 428 405 if (scheduleView.Content != null) { 429 406 scheduleView.Content.Clear(); 430 407 } 408 431 409 HiveAdminClient.Instance.ResetDowntime(); 432 410 } … … 434 412 435 413 private void UpdateResources() { 436 ResetView();437 438 414 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(); 443 416 HiveAdminClient.Instance.Refresh(); 444 417 Content = HiveAdminClient.Instance.Resources; 445 } 446 catch (MessageSecurityException) { 447 ShowMessageSecurityException(); 448 } 449 catch (AnonymousUserException) { 418 } catch (AnonymousUserException) { 450 419 ShowHiveInformationDialog(); 451 420 } 452 421 } 453 422 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 } 457 469 } 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()); 460 481 } 461 482 462 483 private void ShowHiveInformationDialog() { 463 if (this.InvokeRequired) { 464 Invoke(new Action(ShowHiveInformationDialog)); 465 } else { 484 if (InvokeRequired) Invoke((Action)ShowHiveInformationDialog); 485 else { 466 486 using (HiveInformationDialog dialog = new HiveInformationDialog()) { 467 487 dialog.ShowDialog(this); … … 469 489 } 470 490 } 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 532 492 } 533 493 }
Note: See TracChangeset
for help on using the changeset viewer.