1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
4 | *
|
---|
5 | * This file is part of HeuristicLab.
|
---|
6 | *
|
---|
7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
8 | * it under the terms of the GNU General Public License as published by
|
---|
9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
10 | * (at your option) any later version.
|
---|
11 | *
|
---|
12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | * GNU General Public License for more details.
|
---|
16 | *
|
---|
17 | * You should have received a copy of the GNU General Public License
|
---|
18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
19 | */
|
---|
20 | #endregion
|
---|
21 |
|
---|
22 | using System;
|
---|
23 | using System.ComponentModel;
|
---|
24 | using System.Drawing;
|
---|
25 | using System.Linq;
|
---|
26 | using System.Windows.Forms;
|
---|
27 | using HeuristicLab.Clients.Access;
|
---|
28 | using HeuristicLab.Clients.Hive.Views;
|
---|
29 | using HeuristicLab.Common.Resources;
|
---|
30 | using HeuristicLab.Core;
|
---|
31 | using HeuristicLab.Core.Views;
|
---|
32 | using HeuristicLab.MainForm;
|
---|
33 |
|
---|
34 | namespace HeuristicLab.Clients.Hive.Administrator.Views {
|
---|
35 | [View("Resources View")]
|
---|
36 | [Content(typeof(IItemList<Resource>), false)]
|
---|
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 |
|
---|
48 | public new IItemList<Resource> Content {
|
---|
49 | get { return (IItemList<Resource>)base.Content; }
|
---|
50 | set { base.Content = value; }
|
---|
51 | }
|
---|
52 |
|
---|
53 | public ResourcesView() {
|
---|
54 | InitializeComponent();
|
---|
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 |
|
---|
74 | protected override void RegisterContentEvents() {
|
---|
75 | base.RegisterContentEvents();
|
---|
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 | }
|
---|
85 |
|
---|
86 | protected override void OnContentChanged() {
|
---|
87 | base.OnContentChanged();
|
---|
88 | if (Content == null) {
|
---|
89 | slaveView.Content = null;
|
---|
90 | scheduleView.Content = null;
|
---|
91 | treeSlaveGroup.Nodes.Clear();
|
---|
92 | } else {
|
---|
93 | treeSlaveGroup.Nodes.Clear();
|
---|
94 |
|
---|
95 | //rebuild
|
---|
96 | TreeNode ungrp = new TreeNode(UngroupedGroupName);
|
---|
97 | ungrp.ImageIndex = slaveGroupImageIndex;
|
---|
98 | ungrp.SelectedImageIndex = ungrp.ImageIndex;
|
---|
99 | var newGroup = new SlaveGroup();
|
---|
100 | newGroup.Name = UngroupedGroupName;
|
---|
101 | newGroup.Id = Guid.NewGuid();
|
---|
102 | newGroup.Description = "Contains slaves which are in no group";
|
---|
103 | ungrp.Tag = newGroup;
|
---|
104 |
|
---|
105 | foreach (Resource g in Content.OrderBy(x => x.Name)) {
|
---|
106 | if (g.GetType() == typeof(SlaveGroup)) {
|
---|
107 | //root node
|
---|
108 | if (g.ParentResourceId == null) {
|
---|
109 | TreeNode tn = new TreeNode();
|
---|
110 | tn.ImageIndex = slaveGroupImageIndex;
|
---|
111 | tn.SelectedImageIndex = tn.ImageIndex;
|
---|
112 |
|
---|
113 | tn.Tag = g;
|
---|
114 | tn.Text = g.Name;
|
---|
115 | if (g.OwnerUserId == Access.UserInformation.Instance.User.Id) tn.BackColor = ownedResourceColor;
|
---|
116 |
|
---|
117 | BuildSlaveGroupTree(g, tn);
|
---|
118 | treeSlaveGroup.Nodes.Add(tn);
|
---|
119 | }
|
---|
120 | } else if (g.GetType() == typeof(Slave)) {
|
---|
121 | if (g.ParentResourceId == null) {
|
---|
122 | var stn = new TreeNode(g.Name);
|
---|
123 | stn.ImageIndex = slaveImageIndex;
|
---|
124 | stn.SelectedImageIndex = stn.ImageIndex;
|
---|
125 | stn.Tag = g;
|
---|
126 | if (g.OwnerUserId == Access.UserInformation.Instance.User.Id) stn.BackColor = ownedResourceColor;
|
---|
127 | ungrp.Nodes.Add(stn);
|
---|
128 | }
|
---|
129 | }
|
---|
130 | }
|
---|
131 | treeSlaveGroup.Nodes.Add(ungrp);
|
---|
132 | }
|
---|
133 | }
|
---|
134 |
|
---|
135 | protected override void SetEnabledStateOfControls() {
|
---|
136 | base.SetEnabledStateOfControls();
|
---|
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) {
|
---|
155 | OnContentChanged();
|
---|
156 | if (e.PropertyName == "HbInterval") {
|
---|
157 | UpdateChildHbIntervall(slaveView.Content);
|
---|
158 | }
|
---|
159 | }
|
---|
160 |
|
---|
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);
|
---|
217 | }
|
---|
218 |
|
---|
219 | private void btnAddGroup_Click(object sender, EventArgs e) {
|
---|
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());
|
---|
266 | }
|
---|
267 |
|
---|
268 | private void treeSlaveGroup_DragDrop(object sender, DragEventArgs e) {
|
---|
269 | if (e.Data.GetDataPresent("System.Windows.Forms.TreeNode", false)) {
|
---|
270 | Point pt = ((TreeView)sender).PointToClient(new Point(e.X, e.Y));
|
---|
271 | TreeNode destNode = ((TreeView)sender).GetNodeAt(pt);
|
---|
272 | TreeNode newNode = (TreeNode)e.Data.GetData("System.Windows.Forms.TreeNode");
|
---|
273 |
|
---|
274 | if (destNode.TreeView == newNode.TreeView) {
|
---|
275 | if (destNode.Text == UngroupedGroupName || (destNode.Parent != null && destNode.Parent.Text == UngroupedGroupName)) {
|
---|
276 | MessageBox.Show(string.Format("You can't drag items to the group \"{0}\".{1}This group only contains slaves which haven't yet been assigned to a real group.",
|
---|
277 | UngroupedGroupName, Environment.NewLine), "HeuristicLab Hive Administrator", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
---|
278 | return;
|
---|
279 | }
|
---|
280 |
|
---|
281 | SlaveGroup sgrp = null;
|
---|
282 | TreeNode parentNode = null;
|
---|
283 | if (destNode.Tag != null && destNode.Tag is SlaveGroup) {
|
---|
284 | sgrp = (SlaveGroup)destNode.Tag;
|
---|
285 | parentNode = destNode;
|
---|
286 | } else if (destNode.Parent != null && destNode.Parent.Tag is SlaveGroup) {
|
---|
287 | sgrp = (SlaveGroup)destNode.Parent.Tag;
|
---|
288 | parentNode = destNode.Parent;
|
---|
289 | }
|
---|
290 |
|
---|
291 | if (newNode.Tag is SlaveGroup && CheckParentsEqualsMovedNode(parentNode, newNode)) {
|
---|
292 | return;
|
---|
293 | }
|
---|
294 |
|
---|
295 | SlaveGroup parent = (SlaveGroup)parentNode.Tag;
|
---|
296 |
|
---|
297 | if (parent.OwnerUserId != null && !IsAuthorized(parent)) {
|
---|
298 | MessageBox.Show(string.Format("You don't have the permissions to drag items to the group \"{0}\".", ((Resource)parentNode.Tag).Name),
|
---|
299 | "HeuristicLab Hive Administrator", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
---|
300 | return;
|
---|
301 | }
|
---|
302 |
|
---|
303 | if (sgrp != null && newNode.Tag != null) {
|
---|
304 | //save parent group to get an id
|
---|
305 | if (sgrp.Id == Guid.Empty) {
|
---|
306 | sgrp.Store();
|
---|
307 | }
|
---|
308 |
|
---|
309 | if (newNode.Tag is Slave) {
|
---|
310 | Slave slave = (Slave)newNode.Tag;
|
---|
311 | if (slave.ParentResourceId == null || (slave.ParentResourceId != null && slave.ParentResourceId != sgrp.Id)) {
|
---|
312 | slave.ParentResourceId = sgrp.Id;
|
---|
313 | newNode.Remove();
|
---|
314 | parentNode.Nodes.Clear();
|
---|
315 | BuildSlaveGroupTree(sgrp, parentNode);
|
---|
316 | }
|
---|
317 | } else if (newNode.Tag is SlaveGroup) {
|
---|
318 | SlaveGroup slaveGroup = (SlaveGroup)newNode.Tag;
|
---|
319 | if (slaveGroup.ParentResourceId == null || (slaveGroup.ParentResourceId != null && slaveGroup.ParentResourceId != sgrp.Id)) {
|
---|
320 | slaveGroup.ParentResourceId = sgrp.Id;
|
---|
321 | newNode.Remove();
|
---|
322 | parentNode.Nodes.Clear();
|
---|
323 | BuildSlaveGroupTree(sgrp, parentNode);
|
---|
324 | }
|
---|
325 | }
|
---|
326 | }
|
---|
327 | }
|
---|
328 | }
|
---|
329 | }
|
---|
330 |
|
---|
331 | private void treeSlaveGroup_ItemDrag(object sender, ItemDragEventArgs e) {
|
---|
332 | TreeNode sourceNode = (TreeNode)e.Item;
|
---|
333 | if (IsAuthorized((Resource)sourceNode.Tag))
|
---|
334 | DoDragDrop(sourceNode, DragDropEffects.All);
|
---|
335 | }
|
---|
336 |
|
---|
337 | private void treeSlaveGroup_DragEnter(object sender, DragEventArgs e) {
|
---|
338 | e.Effect = DragDropEffects.Move;
|
---|
339 | }
|
---|
340 |
|
---|
341 | private void treeSlaveGroup_DragOver(object sender, DragEventArgs e) {
|
---|
342 | e.Effect = DragDropEffects.Move;
|
---|
343 | }
|
---|
344 |
|
---|
345 | private void treeSlaveGroup_QueryContinueDrag(object sender, QueryContinueDragEventArgs e) {
|
---|
346 | e.Action = DragAction.Continue;
|
---|
347 | }
|
---|
348 |
|
---|
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 {
|
---|
398 | treeSlaveGroup.Nodes.Clear();
|
---|
399 |
|
---|
400 | if (slaveView.Content != null && slaveView.Content is SlaveGroup) {
|
---|
401 | slaveView.Content.PropertyChanged -= SlaveViewContent_PropertyChanged;
|
---|
402 | }
|
---|
403 |
|
---|
404 | slaveView.Content = null;
|
---|
405 | if (scheduleView.Content != null) {
|
---|
406 | scheduleView.Content.Clear();
|
---|
407 | }
|
---|
408 |
|
---|
409 | HiveAdminClient.Instance.ResetDowntime();
|
---|
410 | }
|
---|
411 | }
|
---|
412 |
|
---|
413 | private void UpdateResources() {
|
---|
414 | try {
|
---|
415 | ResetView();
|
---|
416 | HiveAdminClient.Instance.Refresh();
|
---|
417 | Content = HiveAdminClient.Instance.Resources;
|
---|
418 | } catch (AnonymousUserException) {
|
---|
419 | ShowHiveInformationDialog();
|
---|
420 | }
|
---|
421 | }
|
---|
422 |
|
---|
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 | }
|
---|
469 | } else {
|
---|
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());
|
---|
481 | }
|
---|
482 |
|
---|
483 | private void ShowHiveInformationDialog() {
|
---|
484 | if (InvokeRequired) Invoke((Action)ShowHiveInformationDialog);
|
---|
485 | else {
|
---|
486 | using (HiveInformationDialog dialog = new HiveInformationDialog()) {
|
---|
487 | dialog.ShowDialog(this);
|
---|
488 | }
|
---|
489 | }
|
---|
490 | }
|
---|
491 | #endregion
|
---|
492 | }
|
---|
493 | }
|
---|